from header_game_menus import *
from header_parties import *
from header_items import *
from header_mission_templates import *
from header_music import *
from header_terrain_types import *

from module_constants import *

####################################################################################################################
#  (menu-id, menu-flags, menu_text, mesh-name, [<operations>], [<options>]),
#
#   Each game menu is a tuple that contains the following fields:
#  
#  1) Game-menu id (string): used for referencing game-menus in other files.
#     The prefix menu_ is automatically added before each game-menu-id
#
#  2) Game-menu flags (int). See header_game_menus.py for a list of available flags.
#     You can also specify menu text color here, with the menu_text_color macro
#  3) Game-menu text (string).
#  4) mesh-name (string). Not currently used. Must be the string "none"
#  5) Operations block (list). A list of operations. See header_operations.py for reference.
#     The operations block is executed when the game menu is activated.
#  6) List of Menu options (List).
#     Each menu-option record is a tuple containing the following fields:
#   6.1) Menu-option-id (string) used for referencing game-menus in other files.
#        The prefix mno_ is automatically added before each menu-option.
#   6.2) Conditions block (list). This must be a valid operation block. See header_operations.py for reference. 
#        The conditions are executed for each menu option to decide whether the option will be shown to the player or not.
#   6.3) Menu-option text (string).
#   6.4) Consequences block (list). This must be a valid operation block. See header_operations.py for reference. 
#        The consequences are executed for the menu option that has been selected by the player.
#
#
# Note: The first Menu is the initial character creation menu.
####################################################################################################################

game_menus = [

("start_game_0", 18374686479671624192,
"Welcome, adventurer, to Mount and Blade: Warband, Prophesy of Pendor. Before beginning the game you must create your character. While in a traditional medieval society war and politics are usually dominated by male members of the nobility, this is emphatically not the case in Pendor - men and women are equals in battle, at conquest and either gender may become king or queen. That does not however mean that you should not choose to play a character who is not of noble birth. Nobles may have a somewhat easier start, but commoners can attain all of the same goals -- and in fact may have a much more interesting if more challenging early game.",
"none", 
[
    (assign, "$astraea_aid_snd", 0),
    (assign, "$wrath_of_indar", 0),
    (assign, "$damia_command", 0),
    (assign, "$claws_of_vejovis", 0),
    (assign, "$eunomia_warning", 0),
    (assign, "$hafsigla_wrath", 0),
    (assign, "$thallo_defend", 0),
    (assign, "$vata_command", 0),
    (assign, "$ullbow", 0),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_start_game_1"),
    ], "."),

    ("go_back", [],
    "Go back",
    [
        (change_screen_quit),
    ], "."),

]),

("start_phase_2", 512,
"By the grace of the divine, you arrive in Pendor, a land plagued by constant strife for over 150 years.  You have accepted a daunting challenge:  to stave off the influence of evil, reunite the warring factions of the old Kingdom, and fulfill the Prophesy of Pendor, as foretold by the mad wanderer, Madigan.^^These are dangerous lands, where many powers, great and small, vie against one another for supremacy.  Here you will find Honor and Nobility but also Deceit and Skullduggery.  There will be Valorous Knights, and Black-Hearted Assassins. You will leave your past behind to start a new life.  Pendor is not your typical medieval country.  Women and men have equal chances of successs and failure in Pendor.  If you succeed, you will fulfill another destiny, creating a new possibility in the infinite dimensions of reality.  Your choices may create a new thread in the weave for the Oracle to choose, and offer the possibility that your actions may save us all.^^Drawn by the stories you hear about Pendor and its kingdoms, you...",
"none", [],
[
    ("town_1", 
    [
        (eq, "$current_startup_quest_phase", 0),
        (store_relation, ":var_0", "fac_kingdom_1", "fac_player_faction"),
        (ge, ":var_0", 0),
    ],
    "join a caravan to Sarleon, in the Kingdom of Sarleon.",
    [
        (assign, "$current_town", "p_town_6"),
        (assign, "$g_starting_town", "$current_town"),
        (assign, "$g_journey_string", "str_journey_to_sarleon"),
        (jump_to_menu, "mnu_start_phase_2_5"),
    ], "."),

    ("town_2", 
    [
        (eq, "$current_startup_quest_phase", 0),
        (store_relation, ":var_0", "fac_kingdom_2", "fac_player_faction"),
        (ge, ":var_0", 0),
    ],
    "join a caravan to Ravenstern, in the Kingdom of Ravenstern.",
    [
        (assign, "$current_town", "p_town_8"),
        (assign, "$g_starting_town", "$current_town"),
        (assign, "$g_journey_string", "str_journey_to_ravenstern"),
        (jump_to_menu, "mnu_start_phase_2_5"),
    ], "."),

    ("town_3", 
    [
        (eq, "$current_startup_quest_phase", 0),
        (store_relation, ":var_0", "fac_kingdom_3", "fac_player_faction"),
        (ge, ":var_0", 0),
    ],
    "join a caravan to Torbah, in the D'Shar Principalities.",
    [
        (assign, "$current_town", "p_town_10"),
        (assign, "$g_starting_town", "$current_town"),
        (assign, "$g_journey_string", "str_journey_to_torbah"),
        (jump_to_menu, "mnu_start_phase_2_5"),
    ], "."),

    ("town_4", 
    [
        (eq, "$current_startup_quest_phase", 0),
        (store_relation, ":var_0", "fac_kingdom_4", "fac_player_faction"),
        (ge, ":var_0", 0),
    ],
    "take a ship to Javiksholm, in the Fierdsvain.",
    [
        (assign, "$current_town", "p_town_1"),
        (assign, "$g_starting_town", "$current_town"),
        (assign, "$g_journey_string", "str_journey_to_javiksholm"),
        (jump_to_menu, "mnu_start_phase_2_5"),
    ], "."),

    ("town_5", 
    [
        (eq, "$current_startup_quest_phase", 0),
        (store_relation, ":var_0", "fac_kingdom_5", "fac_player_faction"),
        (ge, ":var_0", 0),
    ],
    "take a ship to Janos, in the Empire.",
    [
        (assign, "$current_town", "p_town_5"),
        (assign, "$g_starting_town", "$current_town"),
        (assign, "$g_journey_string", "str_journey_to_janos"),
        (jump_to_menu, "mnu_start_phase_2_5"),
    ], "."),

    ("pop_cheat", 
    [
        (eq, 0, 1),
    ],
    "[TEST] Just let me play!",
    [
        (call_script, "script_get_player_party_morale_values"),
        (party_set_morale, "p_main_party", reg0),
        (party_relocate_near_party, "p_main_party", "p_town_6", 2),
        (troop_sort_inventory, "trp_player"),
        (change_screen_return),
    ], "."),

    ("tutorial_cheat", 
    [
        (eq, 1, 0),
    ],
    "{!}CHEAT!",
    [
        (change_screen_return),
        (assign, "$cheat_mode", 1),
        (set_show_messages, 0),
        (add_xp_to_troop, 15000, "trp_player"),
        (troop_raise_skill, "trp_player", skl_leadership, 7),
        (troop_raise_skill, "trp_player", skl_prisoner_management, 5),
        (troop_raise_skill, "trp_player", skl_inventory_management, 10),
        (party_add_members, "p_main_party", "trp_sarleon_knight", 10),
        (party_add_members, "p_main_party", "trp_rav_knight", 10),
        (party_add_members, "p_main_party", "trp_rav_archer", 10),
        (party_add_members, "p_main_party", "trp_sarleon_arm_longbowman", 10),
        (troop_add_item, "trp_player", "itm_scale_armor", 0),
        (troop_add_item, "trp_player", "itm_full_helm", 0),
        (troop_add_item, "trp_player", "itm_awlpike", 0),
        (set_show_messages, 1),
        (try_for_range, ":var_0", "scn_town_1_center", "scn_castle_1_exterior"),
            (scene_set_slot, ":var_0", 0, 1),
        (try_end),
        (call_script, "script_get_player_party_morale_values"),
        (party_set_morale, "p_main_party", reg0),
    ], "."),

]),

("start_game_3", 512,
"Choose your scenario:",
"none", 
[
    (assign, "$g_custom_battle_scenario", 0),
    (assign, "$g_custom_battle_scenario", "$g_custom_battle_scenario"),
],
[
    ("go_back", [],
    "Go back",
    [
        (change_screen_quit),
    ], "."),

]),

("tutorial", 512,
"You approach a field where the locals are training with weapons. You can practice here to improve your combat skills.",
"none", 
[
    (try_begin),
        (eq, "$g_tutorial_entered", 1),
        (change_screen_quit),
    (else_try),
        (set_passage_menu, "mnu_tutorial"),
        (assign, "$g_tutorial_entered", 1),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (modify_visitors_at_site, "scn_tutorial_training_ground"),
        (reset_visitors, 0),
        (set_player_troop, "trp_player"),
        (assign, "$g_player_troop", "trp_player"),
        (troop_raise_attribute, "$g_player_troop", ca_strength, 12),
        (troop_raise_attribute, "$g_player_troop", ca_agility, 9),
        (troop_raise_attribute, "$g_player_troop", ca_charisma, 5),
        (troop_raise_skill, "$g_player_troop", skl_shield, 3),
        (troop_raise_skill, "$g_player_troop", skl_athletics, 2),
        (troop_raise_skill, "$g_player_troop", skl_riding, 3),
        (troop_raise_skill, "$g_player_troop", skl_power_strike, 1),
        (troop_raise_skill, "$g_player_troop", skl_power_draw, 5),
        (troop_raise_skill, "$g_player_troop", skl_weapon_master, 4),
        (troop_raise_skill, "$g_player_troop", skl_ironflesh, 1),
        (troop_raise_skill, "$g_player_troop", skl_horse_archery, 6),
        (troop_raise_proficiency_linear, "$g_player_troop", wpt_one_handed_weapon, 70),
        (troop_raise_proficiency_linear, "$g_player_troop", wpt_two_handed_weapon, 70),
        (troop_raise_proficiency_linear, "$g_player_troop", wpt_polearm, 70),
        (troop_raise_proficiency_linear, "$g_player_troop", wpt_crossbow, 70),
        (troop_raise_proficiency_linear, "$g_player_troop", wpt_throwing, 70),
        (troop_clear_inventory, "$g_player_troop"),
        (troop_add_item, "$g_player_troop", "itm_leather_jerkin", 0),
        (troop_add_item, "$g_player_troop", "itm_leather_boots", 0),
        (troop_add_item, "$g_player_troop", "itm_practice_sword", 0),
        (troop_add_item, "$g_player_troop", "itm_quarter_staff", 0),
        (troop_equip_items, "$g_player_troop"),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 32, "trp_tutorial_fighter_1"),
        (set_visitor, 33, "trp_tutorial_fighter_2"),
        (set_visitor, 34, "trp_tutorial_fighter_3"),
        (set_visitor, 35, "trp_tutorial_fighter_4"),
        (set_visitor, 40, "trp_tutorial_master_archer"),
        (set_visitor, 41, "trp_tutorial_archer_1"),
        (set_visitor, 42, "trp_tutorial_archer_1"),
        (set_visitor, 60, "trp_tutorial_master_horseman"),
        (set_visitor, 61, "trp_tutorial_rider_1"),
        (set_visitor, 62, "trp_tutorial_rider_1"),
        (set_visitor, 63, "trp_tutorial_rider_2"),
        (set_visitor, 64, "trp_tutorial_rider_2"),
        (set_jump_mission, "mt_tutorial_training_ground"),
        (jump_to_scene, "scn_tutorial_training_ground"),
        (change_screen_mission),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (change_screen_quit),
    ], "."),

]),

("reports", 0,
"Character Renown/Prestige: {reg5}^ ^Honor Rating: {reg6}^Prestige spent: {reg9}^Base prestige cost of Honor troops: {reg10}^^Party Morale: {reg8}^Party Size Limit: {reg7}^",
"none", 
[
    (call_script, "script_game_get_party_companion_limit"),
    (assign, ":var_0", reg0),
    (troop_get_slot, ":var_1", "trp_player", slot_troop_renown),
    (assign, reg5, ":var_1"),
    (assign, reg6, "$player_honor"),
    (assign, reg7, ":var_0"),
    (party_get_morale, reg8, "p_main_party"),
    (troop_get_slot, ":var_2", "trp_player", 156),
    (assign, reg9, ":var_2"),
    (assign, reg10, 450),
    (val_sub, reg10, "$player_honor"),
    (val_div, reg10, 10),
    (val_clamp, reg10, 10, 46),
],
[
    ("resume_travelling", [],
    "Resume travelling.",
    [
        (change_screen_return),
    ], "."),

    ("action_view_upgrade_trees", [],
    "View upgrade trees.",
    [
        (assign, "$temp_2", 0),
        (start_presentation, "prsnt_upgrade_trees"),
    ], "."),

    ("cheat_faction_orders", 
    [
        (ge, "$cheat_mode", 1),
    ],
    "{!}Cheat: Faction orders.",
    [
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("view_character_report", [],
    "View character report.",
    [
        (jump_to_menu, "mnu_character_report"),
    ], "."),

    ("view_party_size_report", [],
    "View party size report.",
    [
        (jump_to_menu, "mnu_party_size_report"),
    ], "."),

    ("view_morale_report", [],
    "View party morale report.",
    [
        (jump_to_menu, "mnu_morale_report"),
    ], "."),

    ("view_weekly_budget_report", [],
    "View weekly budget report.",
    [
        (assign, "$g_apply_budget_report_to_gold", 0),
        (start_presentation, "prsnt_budget_report"),
    ], "."),

    ("view_center_income_report", [],
    "View location income report.",
    [
        (jump_to_menu, "mnu_center_income_report"),
    ], "."),

    ("view_victory_condition_report", [],
    "View victory progress.",
    [
        (jump_to_menu, "mnu_victory_progress_report"),
    ], "."),

    ("view_achievement_report", [],
    "View achievements.",
    [
        (assign, "$g_achievement_page_no", 0),
        (start_presentation, "prsnt_achievement_report"),
    ], "."),

    ("status_check", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}NPC status check.",
    [
        (try_for_range, ":var_0", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (main_party_has_troop, ":var_0"),
            (str_store_troop_name, s4, ":var_0"),
            (troop_get_slot, reg3, ":var_0", slot_troop_morality_state),
            (troop_get_slot, reg4, ":var_0", slot_troop_2ary_morality_state),
            (troop_get_slot, reg5, ":var_0", slot_troop_personalityclash_state),
            (troop_get_slot, reg6, ":var_0", slot_troop_personalityclash2_state),
            (troop_get_slot, reg7, ":var_0", slot_troop_personalitymatch_state),
            (display_message, "@{!}{s4}: M{reg3}, 2M{reg4}, PC{reg5}, 2PC{reg6}, PM{reg7}"),
        (try_end),
    ], "."),

    ("view_faction_relations_report", [],
    "View faction relations report.",
    [
        (jump_to_menu, "mnu_faction_relations_report"),
    ], "."),

    ("view_npc_mission_report", [],
    "View companion mission report.",
    [
        (jump_to_menu, "mnu_companion_report"),
    ], "."),

    ("lord_relations", [],
    "View list of known lords by relation.",
    [
        (jump_to_menu, "mnu_lord_relations"),
    ], "."),

    ("courtship_relations", [],
    "View courtship relations.",
    [
        (jump_to_menu, "mnu_courtship_relations"),
    ], "."),

]),

("custom_battle_scene", 18374686479671624192,
"(NO TRANS)",
"none", [],
[
    ("quick_battle_scene_1", [],
    "{!}quick battle scene 1",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_quick_battle_scene_1"),
        (change_screen_mission),
    ], "."),

    ("quick_battle_scene_2", [],
    "{!}quick battle scene 2",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_quick_battle_scene_2"),
        (change_screen_mission),
    ], "."),

    ("quick_battle_scene_3", [],
    "{!}quick battle scene 3",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_quick_battle_scene_3"),
        (change_screen_mission),
    ], "."),

    ("quick_battle_scene_4", [],
    "{!}quick battle scene 4",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_quick_battle_scene_4"),
        (change_screen_mission),
    ], "."),

    ("quick_battle_scene_5", [],
    "{!}quick battle scene 5",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_quick_battle_scene_5"),
        (change_screen_mission),
    ], "."),

    ("go_back", [],
    "{!}Go back",
    [
        (change_screen_quit),
    ], "."),

]),

("custom_battle_end", 512,
"The battle is over. {s1} Your side killed {reg5} enemies and lost {reg6} troops over the battle. You personally slew {reg7} men in the fighting.",
"none", 
[
    (music_set_situation, 0),
    (assign, reg5, "$g_custom_battle_team2_death_count"),
    (assign, reg6, "$g_custom_battle_team1_death_count"),
    (get_player_agent_kill_count, ":var_0"),
    (get_player_agent_kill_count, ":var_1", 1),
    (store_add, reg7, ":var_0", ":var_1"),
    (try_begin),
        (eq, "$g_battle_result", 1),
        (str_store_string, s1, "str_battle_won"),
    (else_try),
        (str_store_string, s1, "str_battle_lost"),
    (try_end),
    (try_begin),
        (ge, "$g_custom_battle_team2_death_count", 100),
        (unlock_achievement, 4),
    (try_end),
],
[
    ("continue", [],
    "Continue.",
    [
        (change_screen_quit),
    ], "."),

]),

("start_game_1", 18374686479671624192,
"Select your character's gender.",
"none", [],
[
    ("start_male", [],
    "Male",
    [
        (troop_set_type, "trp_player", 0),
        (assign, "$character_gender", 0),
        (jump_to_menu, "mnu_start_character_1"),
    ], "."),

    ("start_female", [],
    "Female",
    [
        (troop_set_type, "trp_player", 1),
        (assign, "$character_gender", 1),
        (jump_to_menu, "mnu_start_character_1"),
    ], "."),

    ("start_female_2", [],
    "Pretty Female",
    [
        (troop_set_type, "trp_player", 2),
        (assign, "$character_gender", 2),
        (jump_to_menu, "mnu_start_character_1"),
    ], "."),

    ("go_back", [],
    "Go back",
    [
        (jump_to_menu, "mnu_start_game_0"),
    ], "."),

]),

("start_character_1", 512,
"You were born years ago, in the Land of Barclay, far to the West and South of Pendor.  You never knew your mother, who died when you were young.  Your father was...",
"none", 
[
    (str_clear, s10),
    (str_clear, s11),
    (str_clear, s12),
    (str_clear, s13),
    (str_clear, s14),
    (str_clear, s15),
],
[
    ("start_noble", [],
    "An impoverished and displaced minor Noble from Pendor.",
    [
        (assign, "$background_type", 1),
        (assign, reg3, "$character_gender"),
        (str_store_string, s10, "@You came into the world the {reg3?daughter:son} of impoverished nobility. Your family fled the Southern Pendor city of Janos.  Upon his purchase of a tumbledown manor in an outlying district of Barclay, your father and his old retainers managed to provide you with a good education and trained you from childhood in the duties of the aristocracy and the rigors of life at court. You start with negative relations with the Empire."),
        (jump_to_menu, "mnu_start_character_2"),
    ], "."),

    ("start_merchant", [],
    "A Noble merchant ship Captain.",
    [
        (assign, "$background_type", 2),
        (assign, reg3, "$character_gender"),
        (str_store_string, s10, "@You were born the {reg3?daughter:son} of the Fierdsvain Noble Merchant Captain, who traded between Barclay and the Ports of Pendor, dodging pirates, outwitting corrupt harbor masters and avoiding the vicious Red Brotherhood, which seemed to grow stronger each year.  Your father grew prosperous from his ventures, and paid off the debt on his ship to the Shipmasters Guild in Barclay with a percentage of his earnings.  It was a modest life but he provided you with a good education and a talent for making profit and opening new markets. You start with positive relations with the Fierdsvain."),
        (jump_to_menu, "mnu_start_character_2"),
    ], "."),

    ("start_guard", [],
    "A Knight of an outlawed Knighthood Order.",
    [
        (assign, "$background_type", 3),
        (assign, reg3, "$character_gender"),
        (str_store_string, s10, "@When you were a child, your father earned a respectable living as a master-at-arms in Barclay, hiring out to those who could pay for his services.  He had great skill with a sword and taught you all he knew, and you became an expert bladesman.  He was rough and callous, but fair.  He spoke only once of the Knighthood Order to which he belonged, and then only said that it had been outlawed by order of the King of Sarleon.  He refused to answer your many questions about his deeds in the Order, saying only that he preferred not to speak of it in the future.. You start with negative relations with Sarleon."),
        (jump_to_menu, "mnu_start_character_2"),
    ], "."),

    ("start_forester", [],
    "A retired noble adventurer",
    [
        (assign, "$background_type", 4),
        (assign, reg3, "$character_gender"),
        (str_store_string, s11, "@{reg3?daughter:son}"),
        (str_store_string, s10, "@You were the {reg3?daughter:son} of a man who in his youth had travelled with a band of adventurers.  On many a night, you listened raptly to your father's tales of bravery, adventure and sacrifice. He worked as a Sheriff and Warden in the outlying towns of Eastern Barclay.  He was often gone, tracking down and capturing the poachers, outlaws and bandits who plagued the forests where you grew up.  He taught you how to survive in the wilds, to fight, and how to spot and avoid danger."),
        (jump_to_menu, "mnu_start_character_2"),
    ], "."),

    ("start_nomad", [],
    "A banished chieftain's son from the D'Shar Steppes.",
    [
        (assign, "$background_type", 5),
        (assign, reg3, "$character_gender"),
        (str_store_string, s11, "@{reg3?daughter:son}"),
        (str_store_string, s10, "@You were a nomadic child, living in a wagon on the road, travelling from place to place, camping for no more than half a year before moving on.  Your father was born on the D'Shar Plains and told you many stories of how his people lived and fought, inspiring you with pride in your ancestry.  Years ago, when their father died, his older brother had banished him from his tribe.  He gathered up his wife and few possessions and moved to the Northern Plains of Barclay, where you were born. He taught you how to fight, and how to survive through self-reliance.  He was joined by other D'shar outcasts and these outcasts formed their own new tribe, living off the land and carrying on the traditions of their homeland accross the Eastern Sea. You start with negative relations with the D'Shar."),
        (jump_to_menu, "mnu_start_character_2"),
    ], "."),

    ("start_thief", [],
    "A mysterious figure who told you nothing of his past.",
    [
        (assign, "$background_type", 6),
        (assign, reg3, "$character_gender"),
        (str_store_string, s10, "@Growing up in the poor section of Barclay's waterfront district, you received very little 'formal' education. Your father taught you from a young age how to defend yourself, and how to spot and avoid danger. When you were a bit older, he taught you about herbs, poisons, and antidotes, and how to keep someone alive when they were wounded.  He never stepped in to offer you protection from the local bullies, but insisted that you fight your own battles.  He would often leave for extended periods of time, offering no explanation of where he was going, or saying when he would return.  You raised yourself and sometimes had to resort to petty theft just to survive. Still, these difficult years made you streetwise, sharp to the secrets of cities and their shadowy back alley ways."),
        (jump_to_menu, "mnu_start_character_2"),
    ], "."),

    ("go_back", [],
    "Go back",
    [
        (jump_to_menu, "mnu_start_game_1"),
    ], "."),

]),

("start_character_2", 0,
"{s10}^^ In your youth, you had very little idle time, as your father .. ",
"none", [],
[
    ("page", [],
    "arranged for you to serve a minor Barclay noble.",
    [
        (assign, "$background_answer_2", 0),
        (assign, reg3, "$character_gender"),
        (str_store_string, s11, "@As a {reg3?girl:boy} growing out of childhood, you were sent to live in the court of one of the many minor outlying baronies of Barclay.  There, your first lessons were in humility, as you waited upon the lords and ladies of the household.  From their chess games, their gossip, and their poems of great deeds and courtly love, you quickly began to learn of the conflicts of adult life and competition. You learned even more from the rough games of other children, who fought with sticks in imitation of their elders' sword battles."),
        (jump_to_menu, "mnu_start_character_3"),
    ], "."),

    ("apprentice", [],
    "sent you to become an apprentice to the local guilded craftsman.",
    [
        (assign, "$background_answer_2", 1),
        (assign, reg3, "$character_gender"),
        (str_store_string, s11, "@As a {reg3?girl:boy} growing out of childhood, you apprenticed with a local craftsman to learn his trade. After you spent years working hard and studying harder under your master, he promoted you to journeyman. Later, he employed you as a fully-paid craftsman until you decided it was time to move on."),
        (jump_to_menu, "mnu_start_character_3"),
    ], "."),

    ("stockboy", [],
    "put you in the care of a successful merchant.",
    [
        (assign, "$background_answer_2", 4),
        (assign, reg3, "$character_gender"),
        (str_store_string, s11, "@As a {reg3?girl:boy} growing out of childhood, you apprenticed to a wealthy merchant, learning your trade by managing inventories, selling merchandise, and travelling with his caravans.  It was a hard life at first, but it grew easier as you learned how to pry out information the art of buying low and selling high, and how to leave a customer thinking he'd beaten you, and driven the harder bargain himself."),
        (jump_to_menu, "mnu_start_character_3"),
    ], "."),

    ("urchin", [],
    "left you to fend for yourself.",
    [
        (assign, "$background_answer_2", 2),
        (assign, reg3, "$character_gender"),
        (str_store_string, s11, "@As a {reg3?girl:boy} barely emerged from childhood, you lived on the streets, doing whatever you had to, just to survive.  You begged, stole and worked for gangs to earn your bread, living only from day to day in a violent world, frequently only one step ahead of the law and others who wished you ill."),
        (jump_to_menu, "mnu_start_character_3"),
    ], "."),

    ("nomad", [],
    "sent you out on your own to hunt in the wilds.",
    [
        (assign, "$background_answer_2", 3),
        (assign, reg3, "$character_gender"),
        (str_store_string, s11, "@As a very young {reg3?girl:boy}, before you were out of childhood, you rode the great steppes on a horse of your own, learning the paths through the grass and the desert.  Though you sometimes went hungry, you became a skillful hunter and pathfinder in this trackless country.  Your body grew lean and muscular as you mastered the nomad's way of life."),
        (jump_to_menu, "mnu_start_character_3"),
    ], "."),

    ("go_back", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_start_character_1"),
    ], "."),

]),

("start_character_3", 512,
"{s11}^^ Then, after what seemed an eternity, your life changed. You were given the opportunity to become",
"none", 
[
    (assign, reg3, "$character_gender"),
],
[
    ("squire", 
    [
        (eq, "$character_gender", 0),
    ],
    "A squire.",
    [
        (assign, "$background_answer_3", 8),
        (str_store_string, s14, "@{reg3?daughter:man}"),
        (str_store_string, s12, "@Though the distinction felt sudden to you, somewhere along the way you had become a {reg3?woman:man}, and the whole world seemed to change around you.  When you were named squire to a noble at court, you practiced long hours with weapons, learning how to give hard knocks without hesitation and how to take them with fortitude.  You were instructed in your obligations to your lord, and your duties to those who would one day be your vassals.  In addition to learning the chivalric ideal, you also learned about the less attractive side of the noble life -- from old warriors' stories of ruthless power politics, betrayals and usurpations, of men who used guile, as well as valor, to achieve their aims."),
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

    ("lady", 
    [
        (neg|eq, "$character_gender", 0),
    ],
    "A lady-in-waiting.",
    [
        (assign, "$background_answer_3", 9),
        (str_store_string, s14, "@{reg3?daughter:man}"),
        (str_store_string, s13, "@{reg3?woman:man}"),
        (str_store_string, s12, "@Though the distinction felt sudden to you, somewhere along the way you had become a {s13}, and the whole world seemed to change around you.  You joined the tightly-knit circle of women at court, ladies who lived for the appearance of propriety, the wives and mistresses of noblemen, as well as maidens who had yet to find a husband.  Even here, however, you found politics at work, as the ladies schemed for prominence and fought each other bitterly just to catch the eye of whatever unmarried man was currently in fashion at court.  You soon learned ways of turning these situations to your own advantage. With that knowledge came the realisation that you could yourself wield great influence in the world, if you applied a little subtlety to gain your own way."),
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

    ("troubadour", [],
    "A Bard.",
    [
        (assign, "$background_answer_3", 7),
        (str_store_string, s14, "@{reg3?daughter:man}"),
        (str_store_string, s13, "@{reg3?woman:man}"),
        (str_store_string, s12, "@Though the distinction felt sudden to you, somewhere along the way you had become a {s13}, and the whole world seemed to change around you.  You set out on your own with nothing but your instrument slung over your shoulder and your voice.  It was a poor existence, and you spent many a hungry night when people failed to appreciate your music, but you managed to get by on your music alone. As the years went by you became adept at playing to the drunken crowds in the taverns, and even better at talking anyone out of whatever you wanted."),
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

    ("student", [],
    "A scholar at the Barclay university.",
    [
        (assign, "$background_answer_3", 10),
        (str_store_string, s12, "@Though the distinction felt sudden to you, somewhere along the way you had become a {reg3?woman:man}, and the whole world seemed to change around you.  You found yourself a student at university in one of the great cities, where you studied theology, philosophy, and medicine, though not all your lessons were learned in the lecture halls.  Sometimes, you joined your fellows as they roamed the alleys in search of wine, women, or a good fight.  You learned firsthand how to set a broken jaw, and how to persuade an angry townsman to set down his club and accept cash compensation for the destruction of his shop."),
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

    ("peddler", [],
    "A self employed merchant.",
    [
        (assign, "$background_answer_3", 5),
        (str_store_string, s14, "@{reg3?daughter:man}"),
        (str_store_string, s13, "@{reg3?woman:man}"),
        (str_store_string, s12, "@Though the distinction felt sudden to you, somewhere along the way you had become a {s13}, and the whole world seemed to change around you.  Heeding the call of the open road, you travelled from village to village buying and selling.  It was not a rich existence, but you became a master at negotiating a good price from even the most miserly elders. Soon, you knew, you would be well-placed to start your own trading empire..."),
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

    ("craftsman", [],
    "An engineer and builder.",
    [
        (assign, "$background_answer_3", 4),
        (str_store_string, s14, "@{reg3?daughter:man}"),
        (str_store_string, s13, "@{reg3?woman:man}"),
        (str_store_string, s12, "@Though the distinction felt sudden to you, somewhere along the way you had become a {s13}, and the whole world seemed to change around you.  You pursued a career as an apprentice engineer and builder, crafting plans for homes, castles and towns.  As time wore on you became a master of your trade, and your work started to bring you high prices.  With food on your table and logs on your fire, you could take pride in your work and your growing reputation."),
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

    ("poacher", [],
    "A tracker and a hunter.",
    [
        (assign, "$background_answer_3", 3),
        (str_store_string, s14, "@{reg3?daughter:man}"),
        (str_store_string, s13, "@{reg3?woman:man}"),
        (str_store_string, s12, "@Though the distinction felt sudden to you, somewhere along the way you had become a {s13}, and the whole world seemed to change around you.  Dissatisfied with the common man's desperate scrabble for coin, you took to the forests and wilderness and decided to help yourself to its bounty. You hunted stags, boars and geese and sold  the precious meat on the sly. You cut down trees right under the forest watchmen's noses and turned them into firewood that warmed many a freezing home during winter. Your enterprise yielded more than a few silvers, of course."),
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

    ("go_back", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_start_character_2"),
    ], "."),

]),

("start_character_4", 512,
"{s12}^^But as the fates would have it, everything in your world changed suddenly. You had no choice but to leave the lands of Barclay and strike out for Pendor because of..",
"none", [],
[
    ("revenge", [],
    "Personal revenge.",
    [
        (assign, "$background_answer_4", 1),
        (str_store_string, s13, "@Only you know what caused you to give up your old life and become an adventurer.  Still, your choice to leave was not difficult, with rage burning so brightly in your heart.  You want vengeance. You want justice. You know that what was done to you cannot be undone, but you demand repayment for those wrongs in blood..."),
        (jump_to_menu, "mnu_choose_skill"),
    ], "."),

    ("death", [],
    "The loss of a loved one.",
    [
        (assign, "$background_answer_4", 2),
        (str_store_string, s13, "@Only you know what caused you to give up your old life and become an adventurer.  All you can say is that you couldn't bear to stay, not with the memories of those you loved so close and so painful. Perhaps your new life will let you forget, and bring honor to the name that you can no longer bear to speak..."),
        (jump_to_menu, "mnu_choose_skill"),
    ], "."),

    ("wanderlust", [],
    "Wanderlust.",
    [
        (assign, "$background_answer_4", 3),
        (str_store_string, s13, "@Only you know what caused you to give up your old life and become an adventurer.  You're not even sure when your home became a prison, when the familiar became mundane, but your dreams of wandering have taken over your life.  Whether you yearned for some faraway place or merely for the open road and the freedom to travel, you could no longer bear to stay in the same place. You simply left and never looked back..."),
        (jump_to_menu, "mnu_choose_skill"),
    ], "."),

    ("disown", [],
    "Being forced out of your home.",
    [
        (assign, "$background_answer_4", 5),
        (str_store_string, s13, "@Only you know what caused you to give up your old life and become an adventurer.  You know, however, that you cannot go back, because you left nothing behind.  Your home and family are gone now, and you must face the fact that you're out in the wide world all alone, free to sink or swim on your own..."),
        (jump_to_menu, "mnu_choose_skill"),
    ], "."),

    ("greed", [],
    "The lure of gold, the bright prospects of opportunity and the thrill of adventure.",
    [
        (assign, "$background_answer_4", 6),
        (str_store_string, s13, "@Only you know what caused you to give up your old life and become an adventurer.  To others, it appears that you seek a life of excitement and adventure with all the riches, power and renown that go with them.  You want your name spoken by the nobility with respect and perhaps even fear.  You want the world, and you won't let anyone hinder your efforts to get it..."),
        (jump_to_menu, "mnu_choose_skill"),
    ], "."),

    ("go_back", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_start_character_3"),
    ], "."),

]),

("choose_skill", 512,
"{s13}",
"none", 
[
    (assign, "$current_string_reg", 10),
    (assign, ":var_0", 0),
    (try_begin),
        (neg|eq, "$character_gender", 0),
        (str_store_string, s14, "str_woman"),
    (else_try),
        (str_store_string, s14, "str_man"),
    (try_end),
    (try_begin),
        (eq, "$background_type", 1),
        (str_store_string, s15, "str_noble"),
        (val_sub, ":var_0", 1),
    (else_try),
        (str_store_string, s15, "str_common"),
    (try_end),
    (try_begin),
        (eq, ":var_0", -1),
        (str_store_string, s16, "str_may_find_that_you_are_able_to_take_your_place_among_calradias_great_lords_relatively_quickly"),
    (else_try),
        (eq, ":var_0", 0),
        (str_store_string, s16, "str_may_face_some_difficulties_establishing_yourself_as_an_equal_among_calradias_great_lords"),
    (else_try),
        (eq, ":var_0", 1),
        (str_store_string, s16, "str_may_face_great_difficulties_establishing_yourself_as_an_equal_among_calradias_great_lords"),
    (try_end),
],
[
    ("begin_adventuring", [],
    "Become an adventurer and sail to the shores of Pendor.",
    [
        (set_show_messages, 0),
        (play_sound, "snd_nar_the_die_has_been_cast_sail_pendor"),
        (try_begin),
            (eq, "$character_gender", 0),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_attribute, "trp_player", ca_charisma, 1),
        (else_try),
            (troop_raise_attribute, "trp_player", ca_agility, 1),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
        (try_end),
        (troop_raise_attribute, "trp_player", ca_strength, 1),
        (troop_raise_attribute, "trp_player", ca_agility, 1),
        (troop_raise_attribute, "trp_player", ca_charisma, 1),
        (troop_raise_skill, "trp_player", skl_leadership, 1),
        (troop_raise_skill, "trp_player", skl_riding, 1),
        (try_begin),
            (eq, "$background_type", 1),
            (call_script, "script_change_player_relation_with_faction", "fac_kingdom_5", -5),
            (eq, "$character_gender", 0),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_attribute, "trp_player", ca_charisma, 2),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_skill, "trp_player", skl_weapon_master, 1),
            (troop_raise_skill, "trp_player", skl_power_strike, 1),
            (troop_raise_skill, "trp_player", skl_riding, 2),
            (troop_raise_skill, "trp_player", skl_tactics, 2),
            (troop_raise_skill, "trp_player", skl_leadership, 2),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 30),
            (troop_raise_proficiency, "trp_player", wpt_two_handed_weapon, 30),
            (troop_raise_proficiency, "trp_player", wpt_polearm, 30),
            (troop_add_item, "trp_player", "itm_tab_shield_round_a", 24),
            (troop_add_item, "trp_player", "itm_pop_crosshilt_sword", 10),
            (troop_add_item, "trp_player", "itm_pl_265", 0),
            (troop_set_slot, "trp_player", slot_troop_renown, 100),
            (call_script, "script_change_player_honor", 1),
            (troop_add_gold, "trp_player", 300),
        (else_try),
            (eq, "$background_type", 1),
            (neg|eq, "$character_gender", 0),
            (troop_raise_attribute, "trp_player", ca_intelligence, 2),
            (troop_raise_attribute, "trp_player", ca_charisma, 3),
            (troop_raise_skill, "trp_player", skl_wound_treatment, 1),
            (troop_raise_skill, "trp_player", skl_riding, 2),
            (troop_raise_skill, "trp_player", skl_first_aid, 2),
            (troop_raise_skill, "trp_player", skl_leadership, 2),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 40),
            (troop_set_slot, "trp_player", slot_troop_renown, 60),
            (troop_add_item, "trp_player", "itm_tab_shield_round_a", 24),
            (troop_add_item, "trp_player", "itm_pop_crosshilt_sword", 13),
            (troop_add_item, "trp_player", "itm_dress", 24),
            (troop_add_item, "trp_player", "itm_courser", 35),
            (troop_add_gold, "trp_player", 300),
        (else_try),
            (eq, "$background_type", 2),
            (call_script, "script_change_player_relation_with_faction", "fac_kingdom_4", 5),
            (troop_raise_attribute, "trp_player", ca_intelligence, 2),
            (troop_raise_attribute, "trp_player", ca_charisma, 3),
            (troop_raise_skill, "trp_player", skl_riding, 1),
            (troop_raise_skill, "trp_player", skl_leadership, 1),
            (troop_raise_skill, "trp_player", skl_trade, 3),
            (troop_raise_skill, "trp_player", skl_looting, 2),
            (troop_raise_skill, "trp_player", skl_tactics, 1),
            (troop_raise_skill, "trp_player", skl_inventory_management, 3),
            (troop_raise_proficiency, "trp_player", wpt_two_handed_weapon, 20),
            (troop_add_item, "trp_player", "itm_pottery", 0),
            (troop_add_item, "trp_player", "itm_pottery", 0),
            (troop_add_gold, "trp_player", 3000),
            (troop_set_slot, "trp_player", slot_troop_renown, 20),
        (else_try),
            (eq, "$background_type", 3),
            (call_script, "script_change_player_relation_with_faction", "fac_kingdom_1", -5),
            (troop_raise_attribute, "trp_player", ca_strength, 3),
            (troop_raise_attribute, "trp_player", ca_agility, 1),
            (troop_raise_attribute, "trp_player", ca_charisma, 1),
            (troop_raise_skill, "trp_player", skl_ironflesh, 2),
            (troop_raise_skill, "trp_player", skl_power_strike, 1),
            (troop_raise_skill, "trp_player", skl_weapon_master, 2),
            (troop_raise_skill, "trp_player", skl_leadership, 2),
            (troop_raise_skill, "trp_player", skl_trainer, 2),
            (troop_raise_skill, "trp_player", skl_athletics, 2),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 40),
            (troop_raise_proficiency, "trp_player", wpt_two_handed_weapon, 45),
            (troop_raise_proficiency, "trp_player", wpt_polearm, 40),
            (troop_add_item, "trp_player", "itm_tab_shield_kite_b"),
            (troop_add_item, "trp_player", "itm_lance", 5),
            (troop_add_gold, "trp_player", 300),
            (troop_add_item, "trp_player", "itm_pl_312", 0),
            (troop_add_item, "trp_player", "itm_pl_286", 0),
            (troop_add_item, "trp_player", "itm_sword_medieval_c", 0),
            (troop_add_item, "trp_player", "itm_leather_gloves", 0),
            (troop_add_gold, "trp_player", 50),
            (troop_set_slot, "trp_player", slot_troop_renown, 10),
        (else_try),
            (eq, "$background_type", 4),
            (troop_raise_attribute, "trp_player", ca_strength, 2),
            (troop_raise_attribute, "trp_player", ca_agility, 2),
            (troop_raise_skill, "trp_player", skl_power_draw, 2),
            (troop_raise_skill, "trp_player", skl_tracking, 2),
            (troop_raise_skill, "trp_player", skl_pathfinding, 3),
            (troop_raise_skill, "trp_player", skl_spotting, 3),
            (troop_raise_skill, "trp_player", skl_athletics, 3),
            (troop_raise_skill, "trp_player", skl_looting, 2),
            (troop_raise_skill, "trp_player", skl_weapon_master, 1),
            (troop_raise_proficiency, "trp_player", wpt_two_handed_weapon, 20),
            (troop_raise_proficiency, "trp_player", wpt_archery, 50),
            (troop_add_item, "trp_player", "itm_short_bow", 0),
            (troop_add_item, "trp_player", "itm_arrows", 0),
            (troop_add_item, "trp_player", "itm_pl_268", 0),
            (troop_add_gold, "trp_player", 300),
        (else_try),
            (eq, "$background_type", 5),
            (call_script, "script_change_player_relation_with_faction", "fac_kingdom_3", -5),
            (eq, "$character_gender", 0),
            (troop_raise_attribute, "trp_player", ca_strength, 3),
            (troop_raise_attribute, "trp_player", ca_agility, 2),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_skill, "trp_player", skl_power_draw, 3),
            (troop_raise_skill, "trp_player", skl_horse_archery, 3),
            (troop_raise_skill, "trp_player", skl_pathfinding, 3),
            (troop_raise_skill, "trp_player", skl_first_aid, 1),
            (troop_raise_skill, "trp_player", skl_riding, 3),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 20),
            (troop_raise_proficiency, "trp_player", wpt_archery, 40),
            (troop_raise_proficiency, "trp_player", wpt_throwing, 10),
            (troop_add_item, "trp_player", "itm_tab_shield_small_round_a", 5),
            (troop_add_item, "trp_player", "itm_pl_273", 0),
            (troop_add_item, "trp_player", "itm_pop_nomad_robe_brown", 0),
            (troop_add_gold, "trp_player", 15),
            (troop_set_slot, "trp_player", slot_troop_renown, 10),
        (else_try),
            (eq, "$background_type", 5),
            (neg|eq, "$character_gender", 0),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_attribute, "trp_player", ca_agility, 2),
            (troop_raise_attribute, "trp_player", ca_intelligence, 2),
            (troop_raise_skill, "trp_player", skl_wound_treatment, 1),
            (troop_raise_skill, "trp_player", skl_first_aid, 2),
            (troop_raise_skill, "trp_player", skl_pathfinding, 3),
            (troop_raise_skill, "trp_player", skl_riding, 3),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 5),
            (troop_raise_proficiency, "trp_player", wpt_archery, 30),
            (troop_raise_proficiency, "trp_player", wpt_throwing, 15),
            (troop_add_item, "trp_player", "itm_tab_shield_small_round_a", 5),
            (troop_add_item, "trp_player", "itm_pl_443", 0),
            (troop_add_item, "trp_player", "itm_pop_nomad_robe_scarlet", 0),
            (troop_add_item, "trp_player", "itm_hide_boots", 0),
            (troop_add_item, "trp_player", "itm_steppe_horse", 0),
            (troop_add_gold, "trp_player", 120),
        (else_try),
            (eq, "$background_type", 6),
            (troop_raise_attribute, "trp_player", ca_agility, 4),
            (troop_raise_skill, "trp_player", skl_athletics, 3),
            (troop_raise_skill, "trp_player", skl_power_throw, 2),
            (troop_raise_skill, "trp_player", skl_inventory_management, 2),
            (troop_raise_skill, "trp_player", skl_prisoner_management, 2),
            (troop_raise_skill, "trp_player", skl_tactics, 2),
            (troop_raise_skill, "trp_player", skl_persuasion, 2),
            (troop_raise_skill, "trp_player", skl_trade, 1),
            (troop_raise_skill, "trp_player", skl_looting, 2),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 30),
            (troop_raise_proficiency, "trp_player", wpt_throwing, 20),
            (troop_add_item, "trp_player", 461, 0),
            (troop_raise_skill, "trp_player", skl_first_aid, 2),
            (troop_raise_skill, "trp_player", skl_surgery, 1),
            (troop_add_item, "trp_player", "itm_black_hood", 21),
            (troop_add_gold, "trp_player", 25),
        (try_end),
        (try_begin),
            (eq, "$background_answer_2", 0),
            (troop_raise_attribute, "trp_player", ca_charisma, 1),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_skill, "trp_player", skl_power_strike, 1),
            (troop_raise_skill, "trp_player", skl_persuasion, 1),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 15),
            (troop_raise_proficiency, "trp_player", wpt_polearm, 5),
            (call_script, "script_change_troop_renown", "trp_player", 15),
        (else_try),
            (eq, "$background_answer_2", 1),
            (troop_raise_attribute, "trp_player", ca_intelligence, 2),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_add_gold, "trp_player", 200),
            (troop_raise_skill, "trp_player", skl_engineer, 2),
            (troop_raise_skill, "trp_player", skl_trade, 1),
        (else_try),
            (eq, "$background_answer_2", 2),
            (troop_raise_attribute, "trp_player", ca_agility, 2),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_skill, "trp_player", skl_spotting, 1),
            (troop_raise_skill, "trp_player", skl_looting, 2),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 15),
            (troop_raise_proficiency, "trp_player", wpt_throwing, 5),
        (else_try),
            (eq, "$background_answer_2", 3),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_attribute, "trp_player", ca_agility, 1),
            (troop_add_item, "trp_player", "itm_furs", 0),
            (troop_raise_skill, "trp_player", skl_horse_archery, 1),
            (troop_raise_skill, "trp_player", skl_pathfinding, 1),
            (troop_raise_skill, "trp_player", skl_tracking, 1),
            (troop_raise_proficiency, "trp_player", wpt_archery, 25),
            (call_script, "script_change_troop_renown", "trp_player", 5),
        (else_try),
            (eq, "$background_answer_2", 4),
            (troop_raise_attribute, "trp_player", ca_intelligence, 2),
            (troop_raise_attribute, "trp_player", ca_charisma, 1),
            (troop_add_gold, "trp_player", 1000),
            (troop_raise_skill, "trp_player", skl_inventory_management, 2),
            (troop_raise_skill, "trp_player", skl_trade, 2),
        (try_end),
        (try_begin),
            (eq, "$background_answer_3", 3),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_attribute, "trp_player", ca_agility, 1),
            (troop_raise_skill, "trp_player", skl_power_draw, 1),
            (troop_raise_skill, "trp_player", skl_tracking, 1),
            (troop_raise_skill, "trp_player", skl_spotting, 1),
            (troop_raise_skill, "trp_player", skl_athletics, 1),
            (troop_add_gold, "trp_player", 100),
            (troop_raise_proficiency, "trp_player", wpt_polearm, 10),
            (troop_raise_proficiency, "trp_player", wpt_archery, 25),
            (troop_add_item, "trp_player", "itm_axe", 4),
            (troop_add_item, "trp_player", "itm_rawhide_coat", 0),
            (troop_add_item, "trp_player", "itm_hide_boots", 0),
            (troop_add_item, "trp_player", "itm_hunting_bow", 0),
            (troop_add_item, "trp_player", "itm_barbed_arrows", 0),
            (troop_add_item, "trp_player", "itm_saddle_horse", 18),
            (troop_add_item, "trp_player", "itm_dried_meat", 0),
            (troop_add_item, "trp_player", "itm_dried_meat", 0),
            (troop_add_item, "trp_player", "itm_furs", 0),
            (troop_add_item, "trp_player", "itm_furs", 0),
        (else_try),
            (eq, "$background_answer_3", 4),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_skill, "trp_player", skl_weapon_master, 1),
            (troop_raise_skill, "trp_player", skl_engineer, 2),
            (troop_raise_skill, "trp_player", skl_tactics, 2),
            (troop_raise_skill, "trp_player", skl_trade, 1),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 15),
            (troop_add_gold, "trp_player", 700),
            (troop_add_item, "trp_player", "itm_leather_boots", 0),
            (troop_add_item, "trp_player", "itm_coarse_tunic", 0),
            (troop_add_item, "trp_player", "itm_sword_medieval_b", 0),
            (troop_add_item, "trp_player", "itm_light_crossbow", 0),
            (troop_add_item, "trp_player", "itm_bolts", 0),
            (troop_add_item, "trp_player", "itm_tools", 0),
            (troop_add_item, "trp_player", "itm_saddle_horse", 0),
            (troop_add_item, "trp_player", "itm_smoked_fish", 0),
        (else_try),
            (eq, "$background_answer_3", 5),
            (troop_raise_attribute, "trp_player", ca_charisma, 1),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_skill, "trp_player", skl_riding, 1),
            (troop_raise_skill, "trp_player", skl_trade, 2),
            (troop_raise_skill, "trp_player", skl_pathfinding, 1),
            (troop_raise_skill, "trp_player", skl_inventory_management, 2),
            (troop_add_item, "trp_player", "itm_leather_gloves", 0),
            (troop_add_gold, "trp_player", 1000),
            (troop_raise_proficiency, "trp_player", wpt_polearm, 15),
            (troop_add_item, "trp_player", "itm_leather_jacket", 0),
            (troop_add_item, "trp_player", "itm_leather_boots", 0),
            (troop_add_item, "trp_player", "itm_fur_hat", 0),
            (troop_add_item, "trp_player", "itm_quarter_staff", 0),
            (troop_add_item, "trp_player", "itm_light_crossbow", 0),
            (troop_add_item, "trp_player", "itm_bolts", 0),
            (troop_add_item, "trp_player", "itm_saddle_horse", 0),
            (troop_add_item, "trp_player", "itm_sumpter_horse", 0),
            (troop_add_item, "trp_player", "itm_linen", 0),
            (troop_add_item, "trp_player", "itm_pottery", 0),
            (troop_add_item, "trp_player", "itm_wool", 0),
            (troop_add_item, "trp_player", "itm_wool", 0),
            (troop_add_item, "trp_player", "itm_smoked_fish", 0),
        (else_try),
            (eq, "$background_answer_3", 7),
            (troop_raise_attribute, "trp_player", ca_charisma, 3),
            (troop_raise_skill, "trp_player", skl_weapon_master, 1),
            (troop_raise_skill, "trp_player", skl_persuasion, 3),
            (troop_raise_skill, "trp_player", skl_leadership, 2),
            (troop_raise_skill, "trp_player", skl_pathfinding, 1),
            (troop_add_gold, "trp_player", 200),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 25),
            (troop_raise_proficiency, "trp_player", wpt_crossbow, 20),
            (troop_add_item, "trp_player", "itm_tabard", 24),
            (troop_add_item, "trp_player", "itm_leather_boots", 0),
            (troop_add_item, "trp_player", "itm_pop_crosshilt_sword", 0),
            (troop_add_item, "trp_player", "itm_light_crossbow", 0),
            (troop_add_item, "trp_player", "itm_bolts", 0),
            (troop_add_item, "trp_player", "itm_saddle_horse", 0),
            (troop_add_item, "trp_player", "itm_smoked_fish", 0),
        (else_try),
            (eq, "$background_answer_3", 8),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_attribute, "trp_player", ca_agility, 1),
            (troop_raise_skill, "trp_player", skl_trainer, 2),
            (troop_raise_skill, "trp_player", skl_riding, 1),
            (troop_raise_skill, "trp_player", skl_weapon_master, 1),
            (troop_raise_skill, "trp_player", skl_power_strike, 2),
            (troop_raise_skill, "trp_player", skl_leadership, 1),
            (troop_add_gold, "trp_player", 100),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 30),
            (troop_raise_proficiency, "trp_player", wpt_two_handed_weapon, 30),
            (troop_raise_proficiency, "trp_player", wpt_polearm, 30),
            (troop_raise_proficiency, "trp_player", wpt_archery, 10),
            (troop_raise_proficiency, "trp_player", wpt_crossbow, 10),
            (troop_raise_proficiency, "trp_player", wpt_throwing, 10),
            (troop_add_item, "trp_player", "itm_pl_319", 0),
            (troop_add_item, "trp_player", "itm_leather_boots", 0),
            (troop_add_item, "trp_player", "itm_sword_medieval_a", 0),
            (troop_add_item, "trp_player", "itm_light_lance", 0),
            (troop_add_item, "trp_player", "itm_hunting_crossbow", 0),
            (troop_add_item, "trp_player", "itm_bolts", 0),
            (troop_add_item, "trp_player", "itm_saddle_horse", 0),
            (troop_add_item, "trp_player", "itm_chicken", 0),
        (else_try),
            (eq, "$background_answer_3", 9),
            (neg|eq, "$character_gender", 0),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_attribute, "trp_player", ca_charisma, 1),
            (troop_raise_skill, "trp_player", skl_persuasion, 2),
            (troop_raise_skill, "trp_player", skl_riding, 1),
            (troop_raise_skill, "trp_player", skl_wound_treatment, 1),
            (troop_add_item, "trp_player", "itm_dagger", 0),
            (troop_add_item, "trp_player", "itm_light_crossbow", 0),
            (troop_add_item, "trp_player", "itm_bolts", 0),
            (troop_add_item, "trp_player", "itm_courser", 35),
            (troop_add_item, "trp_player", "itm_woolen_hood", 24),
            (troop_add_item, "trp_player", "itm_woolen_dress", 24),
            (troop_add_gold, "trp_player", 100),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 10),
            (troop_raise_proficiency, "trp_player", wpt_crossbow, 35),
            (troop_add_item, "trp_player", "itm_smoked_fish", 0),
        (else_try),
            (eq, "$background_answer_3", 10),
            (troop_raise_attribute, "trp_player", ca_intelligence, 2),
            (troop_raise_skill, "trp_player", skl_weapon_master, 1),
            (troop_raise_skill, "trp_player", skl_surgery, 2),
            (troop_raise_skill, "trp_player", skl_wound_treatment, 2),
            (troop_raise_skill, "trp_player", skl_first_aid, 2),
            (troop_raise_skill, "trp_player", skl_persuasion, 2),
            (troop_add_gold, "trp_player", 80),
            (troop_raise_proficiency, "trp_player", wpt_one_handed_weapon, 20),
            (troop_raise_proficiency, "trp_player", wpt_crossbow, 20),
            (troop_add_item, "trp_player", "itm_linen_tunic", 24),
            (troop_add_item, "trp_player", "itm_woolen_hose", 0),
            (troop_add_item, "trp_player", "itm_sword_medieval_a", 2),
            (troop_add_item, "trp_player", "itm_hunting_crossbow", 0),
            (troop_add_item, "trp_player", "itm_bolts", 0),
            (troop_add_item, "trp_player", "itm_saddle_horse", 31),
            (troop_add_item, "trp_player", "itm_smoked_fish", 0),
            (store_random_in_range, ":var_0", "itm_book_tactics", "itm_spice"),
            (troop_add_item, "trp_player", ":var_0", 0),
        (try_end),
        (try_begin),
            (eq, "$background_answer_4", 1),
            (troop_raise_attribute, "trp_player", ca_strength, 2),
            (troop_raise_skill, "trp_player", skl_power_strike, 1),
            (troop_raise_skill, "trp_player", skl_tactics, 1),
        (else_try),
            (eq, "$background_answer_4", 2),
            (troop_raise_attribute, "trp_player", ca_charisma, 2),
            (troop_raise_skill, "trp_player", skl_ironflesh, 1),
            (troop_raise_skill, "trp_player", skl_first_aid, 1),
        (else_try),
            (eq, "$background_answer_4", 3),
            (troop_raise_attribute, "trp_player", ca_agility, 2),
            (troop_raise_skill, "trp_player", skl_pathfinding, 1),
            (troop_raise_skill, "trp_player", skl_tactics, 1),
        (else_try),
            (eq, "$background_answer_4", 5),
            (troop_raise_attribute, "trp_player", ca_strength, 1),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_skill, "trp_player", skl_weapon_master, 1),
            (troop_raise_skill, "trp_player", skl_tactics, 1),
        (else_try),
            (eq, "$background_answer_4", 6),
            (troop_raise_attribute, "trp_player", ca_agility, 1),
            (troop_raise_attribute, "trp_player", ca_intelligence, 1),
            (troop_raise_skill, "trp_player", skl_looting, 2),
        (try_end),
        (troop_raise_skill, "trp_player", skl_prisoner_management, 2),
        (call_script, "script_update_troop_notes", "trp_player"),
        (troop_sort_inventory, "trp_player"),
        (try_begin),
            (eq, "$background_type", 6),
            (change_screen_return, 0),
        (else_try),
            (jump_to_menu, "mnu_auto_return"),
            (start_presentation, "prsnt_banner_selection"),
        (else_try),
            (change_screen_return, 0),
        (try_end),
        (set_show_messages, 1),
        (play_track, "track_althea_intro_c_audionmusic", 1),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_start_character_4"),
    ], "."),

]),

("past_life_explanation", 512,
"{s3}",
"none", 
[
    (try_begin),
        (gt, "$current_string_reg", 14),
        (assign, "$current_string_reg", 10),
    (try_end),
    (str_store_string_reg, s3, "$current_string_reg"),
    (try_begin),
        (ge, "$current_string_reg", 14),
        (str_store_string, s5, "@Back to the beginning..."),
    (else_try),
        (str_store_string, s5, "@View next segment..."),
    (try_end),
],
[
    ("view_next", [],
    "{s5}",
    [
        (val_add, "$current_string_reg", 1),
        (jump_to_menu, "mnu_past_life_explanation"),
    ], "."),

    ("continue", [],
    "Continue...",
    [
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_choose_skill"),
    ], "."),

]),

("auto_return", 0,
"{!}This menu automatically returns to caller.",
"none", 
[
    (change_screen_return, 0),
],
[
]),

("morale_report", 0,
"{s1}",
"none", 
[
    (call_script, "script_get_player_party_morale_values"),
    (assign, ":var_0", reg0),
    (assign, reg1, "$g_player_party_morale_modifier_party_size"),
    (try_begin),
        (gt, reg1, 0),
        (str_store_string, s2, "@{!} -"),
    (else_try),
        (str_store_string, s2, "str_space"),
    (try_end),
    (assign, reg2, "$g_player_party_morale_modifier_leadership"),
    (try_begin),
        (gt, reg2, 0),
        (str_store_string, s3, "@{!} +"),
    (else_try),
        (str_store_string, s3, "str_space"),
    (try_end),
    (try_begin),
        (gt, "$g_player_party_morale_modifier_no_food", 0),
        (assign, reg7, "$g_player_party_morale_modifier_no_food"),
        (str_store_string, s5, "@^No food:  -{reg7}"),
    (else_try),
        (str_store_string, s5, "str_space"),
    (try_end),
    (assign, reg3, "$g_player_party_morale_modifier_food"),
    (try_begin),
        (gt, reg3, 0),
        (str_store_string, s4, "@{!} +"),
    (else_try),
        (str_store_string, s4, "str_space"),
    (try_end),
    (try_begin),
        (gt, "$g_player_party_morale_modifier_debt", 0),
        (assign, reg6, "$g_player_party_morale_modifier_debt"),
        (str_store_string, s6, "@^Wage debt:  -{reg6}"),
    (else_try),
        (str_store_string, s6, "str_space"),
    (try_end),
    (party_get_morale, reg5, "p_main_party"),
    (store_sub, reg4, reg5, ":var_0"),
    (try_begin),
        (gt, reg4, 0),
        (str_store_string, s7, "@{!} +"),
    (else_try),
        (str_store_string, s7, "str_space"),
    (try_end),
    (assign, reg6, 50),
    (str_store_string, s1, "str_current_party_morale_is_reg5_current_party_morale_modifiers_are__base_morale__50_party_size_s2reg1_leadership_s3reg2_food_variety_s4reg3s5s6_recent_events_s7reg4_total__reg5___"),
    (try_for_range, ":var_1", "fac_kingdom_1", "fac_kingdoms_end"),
        (faction_get_slot, ":var_2", ":var_1", slot_faction_morale_of_player_troops),
        (val_div, ":var_2", 100),
        (neg|eq, ":var_2", 0),
        (assign, reg6, ":var_2"),
        (str_store_faction_name, s9, ":var_1"),
        (str_store_string, s1, "str_s1extra_morale_for_s9_troops__reg6_"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("courtship_relations", 0,
"{s1}",
"none", 
[
    (str_store_string, s1, "str_courtships_in_progress_"),
    (try_for_range, ":var_0", "trp_knight_1_1_wife", "trp_heroes_end"),
        (troop_slot_eq, ":var_0", slot_troop_met, 2),
        (call_script, "script_troop_get_relation_with_troop", "trp_player", ":var_0"),
        (gt, reg0, 0),
        (assign, reg3, reg0),
        (str_store_troop_name, s2, ":var_0"),
        (store_current_hours, ":var_1"),
        (troop_get_slot, ":var_2", ":var_0", slot_troop_last_talk_time),
        (val_sub, ":var_1", ":var_2"),
        (store_div, ":var_3", ":var_1", 24),
        (assign, reg4, ":var_3"),
        (str_store_string, s1, "str_s1_s2_relation_reg3_last_visit_reg4_days_ago"),
    (try_end),
    (str_store_string, s1, "str_s1__poems_known"),
    (try_begin),
        (gt, "$allegoric_poem_recitations", 0),
        (str_store_string, s1, "str_s1_storming_the_castle_of_love_allegoric"),
    (try_end),
    (try_begin),
        (gt, "$tragic_poem_recitations", 0),
        (str_store_string, s1, "str_s1_kais_and_layali_tragic"),
    (try_end),
    (try_begin),
        (gt, "$comic_poem_recitations", 0),
        (str_store_string, s1, "str_s1_a_conversation_in_the_garden_comic"),
    (try_end),
    (try_begin),
        (gt, "$heroic_poem_recitations", 0),
        (str_store_string, s1, "str_s1_helgered_and_kara_epic"),
    (try_end),
    (try_begin),
        (gt, "$mystic_poem_recitations", 0),
        (str_store_string, s1, "str_s1_a_hearts_desire_mystic"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("lord_relations", 0,
"{s1}",
"none", 
[
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_set_slot, ":var_0", slot_troop_temp_slot, 0),
    (try_end),
    (str_clear, s1),
    (try_for_range, ":var_1", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (assign, ":var_2", -100),
        (assign, ":var_3", -1),
        (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (troop_slot_eq, ":var_0", slot_troop_temp_slot, 0),
            (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
            (troop_slot_ge, ":var_0", slot_troop_met, 1),
            (call_script, "script_troop_get_player_relation", ":var_0"),
            (assign, ":var_4", reg0),
            (ge, ":var_4", ":var_2"),
            (assign, ":var_2", ":var_4"),
            (assign, ":var_3", ":var_0"),
        (try_end),
        (gt, ":var_3", -1),
        (str_store_troop_name_link, s4, ":var_3"),
        (assign, reg4, ":var_2"),
        (str_store_string, s1, "@{!}{s1}^{s4}: {reg4}"),
        (troop_set_slot, ":var_3", slot_troop_temp_slot, 1),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("center_income_report", 0,
"{s1}",
"none", 
[
    (str_clear, s2),
    (assign, ":var_0", 0),
    (try_for_range, ":var_1", "p_town_1", "p_salt_mine"),
        (party_slot_eq, ":var_1", slot_town_lord, "trp_player"),
        (party_get_slot, reg1, ":var_1", 290),
        (party_get_slot, reg2, ":var_1", slot_town_prosperity),
        (call_script, "script_get_prosperity_text_to_s50", ":var_1"),
        (str_store_party_name, s4, ":var_1"),
        (str_store_string, s2, "@{s2}^{s4}: Econ: {reg1} - Prosperity: {reg2} {s50} "),
        (val_add, ":var_0", 1),
    (try_end),
    (try_begin),
        (eq, ":var_0", 0),
        (str_store_string, s1, "@Currently no locations owned."),
    (else_try),
        (str_store_string, s1, "@The current fief income is: ^{s2}"),
    (try_end),
],
[
    ("construction", [],
    "View construction report...",
    [
        (jump_to_menu, "mnu_center_construction_report"),
    ], "."),

    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("center_construction_report", 0,
"{s1}",
"none", 
[
    (str_clear, s2),
    (assign, ":var_0", 0),
    (try_for_range, ":var_1", "p_town_1", "p_salt_mine"),
        (party_slot_eq, ":var_1", slot_town_lord, "trp_player"),
        (call_script, "script_get_prosperity_text_to_s50", ":var_1"),
        (str_store_party_name, s4, ":var_1"),
        (try_begin),
            (party_get_slot, ":var_2", ":var_1", slot_center_current_improvement),
            (gt, ":var_2", 0),
            (call_script, "script_get_improvement_details", ":var_2", ":var_1"),
            (gt, reg10, 1),
            (store_current_hours, ":var_3"),
            (party_get_slot, ":var_4", ":var_1", slot_center_improvement_end_hour),
            (val_sub, ":var_4", ":var_3"),
            (store_div, reg8, ":var_4", 24),
            (assign, reg10, 1),
            (try_begin),
                (eq, reg8, 0),
                (assign, reg8, ":var_4"),
                (assign, reg10, 0),
            (try_end),
            (val_max, reg8, 1),
            (store_sub, reg9, reg8, 1),
            (try_begin),
                (eq, ":var_2", 292),
                (str_store_string, s2, "@{s2}^{s4}: {s10} in {reg8} {reg10?day:hour}{reg9?s:}."),
            (else_try),
                (str_store_string, s2, "@{s2}^{s4}: Building {s10} in {reg8} {reg10?day:hour}{reg9?s:}."),
            (try_end),
        (else_try),
            (str_store_string, s2, "@{s2}^{s4}: No construction."),
        (try_end),
        (val_add, ":var_0", 1),
    (try_end),
    (try_begin),
        (eq, ":var_0", 0),
        (str_store_string, s1, "@Currently no locations owned."),
    (else_try),
        (str_store_string, s1, "@Current construction at your fiefs: ^{s2}"),
    (try_end),
],
[
    ("continue", [],
    "Back.",
    [
        (jump_to_menu, "mnu_center_income_report"),
    ], "."),

]),

("victory_progress_report", 0,
"Victory Progress Report^^{s6}^^The Snake Cult is: {s7}^The Jatu are: {s8}^The Mystmountain Barbarians are: {s9}^The Heretics are: {s10}^^Total Armies Spawned: {reg4}^^Armies Remaining:^{s13}^^Noldor Relations: {s12}^^Victory is achieved by:^^- Having one Kingdom remaining.^- The Noldor must have Favorable or better relations with you.^- Every other minor faction must be Obliterated or Destroyed with no outstanding minor faction armies or heroic personalties on the map.",
"none", 
[
    (str_clear, s2),
    (str_clear, s1),
    (str_clear, s3),
    (str_clear, s4),
    (str_clear, s5),
    (str_clear, s6),
    (str_clear, s7),
    (str_clear, s8),
    (str_clear, s9),
    (str_clear, s10),
    (str_clear, s11),
    (str_clear, s12),
    (str_clear, s13),
    (try_for_range, ":var_0", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (assign, ":var_1", 0),
        (try_for_range, ":var_2", "p_town_1", "p_village_1"),
            (store_faction_of_party, ":var_3", ":var_2"),
            (eq, ":var_3", ":var_0"),
            (val_add, ":var_1", 1),
        (try_end),
        (try_begin),
            (eq, ":var_0", "fac_player_supporters_faction"),
            (eq, "$pop_kingdom", 0),
            (str_store_string, s2, "@Long Forgotten"),
        (else_try),
            (neg|eq, ":var_0", "fac_player_supporters_faction"),
            (faction_slot_eq, ":var_0", slot_faction_state, 1),
            (str_store_string, s2, "@Destroyed"),
        (else_try),
            (neg|ge, ":var_1", 3),
            (try_begin),
                (eq, ":var_0", "fac_kingdom_1"),
                (str_store_string, s2, "@Defending the King's Honor"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_2"),
                (str_store_string, s2, "@The Dragon's Fire Grows Cold"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_3"),
                (str_store_string, s2, "@The Windriders bow to the Gale"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_4"),
                (str_store_string, s2, "@The Shieldwall is Pierced"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_5"),
                (str_store_string, s2, "@The Emperor's Will is Weak"),
            (else_try),
                (eq, ":var_0", "fac_player_supporters_faction"),
                (str_store_string, s2, "@A Fledgeling Hope for Pendor"),
            (else_try),
                (str_store_string, s2, "@Very Weak"),
            (try_end),
        (else_try),
            (neg|ge, ":var_1", 7),
            (try_begin),
                (eq, ":var_0", "fac_kingdom_1"),
                (str_store_string, s2, "@Resisting in the King's Name"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_2"),
                (str_store_string, s2, "@The Dragon's Wings are Clipped"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_3"),
                (str_store_string, s2, "@The Windriders fear the Wind"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_4"),
                (str_store_string, s2, "@The Shieldwall Buckles"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_5"),
                (str_store_string, s2, "@The Emperor's Will Wavers"),
            (else_try),
                (eq, ":var_0", "fac_player_supporters_faction"),
                (str_store_string, s2, "@Promising Madigan's Dream"),
            (else_try),
                (str_store_string, s2, "@Weak"),
            (try_end),
        (else_try),
            (try_begin),
                (eq, ":var_0", "fac_kingdom_1"),
                (str_store_string, s2, "@Strong under the King's Banner"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_2"),
                (str_store_string, s2, "@The Dragon is Defiant in the North"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_3"),
                (str_store_string, s2, "@The Windriders are Fiercely United"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_4"),
                (str_store_string, s2, "@The Shieldwall Holds"),
            (else_try),
                (eq, ":var_0", "fac_kingdom_5"),
                (str_store_string, s2, "@The Emperor's Will is Law"),
            (else_try),
                (eq, ":var_0", "fac_player_supporters_faction"),
                (str_store_string, s2, "@Fulfilling the Prophecy"),
            (else_try),
                (str_store_string, s2, "@Strong"),
            (try_end),
        (try_end),
        (str_store_faction_name, s1, ":var_0"),
        (str_store_string, s6, "@{s6}^The {s1}: {s2}"),
    (try_end),
    (store_relation, ":var_4", "fac_noldor_elves", "fac_player_faction"),
    (call_script, "script_faction_relations_text_reporter", ":var_4"),
    (str_store_string, s12, 33),
    (call_script, "script_determine_victory_conditions_and_text", 0),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("companion_report", 0,
"{s7}{s1}",
"none", 
[
    (str_clear, s1),
    (str_store_string, s7, "str_no_companions_in_service"),
    (try_begin),
        (troop_get_slot, ":var_0", "trp_player", slot_troop_spouse),
        (try_begin),
            (troop_get_type, ":var_1", "trp_player"),
            (ge, ":var_1", 1),
            (str_store_string, s8, "str_husband"),
        (else_try),
            (str_store_string, s8, "str_wife"),
        (try_end),
        (try_begin),
            (neg|gt, ":var_0", 0),
            (troop_get_slot, ":var_0", "trp_player", slot_troop_betrothed),
            (str_store_string, s8, "str_betrothed"),
        (try_end),
        (gt, ":var_0", 0),
        (str_store_troop_name, s4, ":var_0"),
        (troop_get_slot, ":var_2", ":var_0", slot_troop_cur_center),
        (try_begin),
            (is_between, ":var_2", "p_town_1", "p_salt_mine"),
            (str_store_party_name, s5, ":var_2"),
        (else_try),
            (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
            (str_store_string, s5, "str_leading_party"),
        (else_try),
            (str_store_string, s5, "str_whereabouts_unknown"),
        (try_end),
        (str_store_string, s3, "str_s4_s8_s5"),
        (str_store_string, s2, 1),
        (str_store_string, s1, "str_s2_s3"),
    (try_end),
    (try_begin),
        (ge, "$cheat_mode", 1),
        (ge, "$npc_to_rejoin_party", 0),
        (str_store_troop_name, s5, "$npc_to_rejoin_party"),
        (str_store_string, s1, "@{!}DEBUG -- {s1}^NPC in rejoin queue: {s5}^"),
    (try_end),
    (try_for_range, ":var_3", "trp_npc_adonja", "trp_kingdom_1_lord"),
        (str_clear, s2),
        (str_clear, s3),
        (try_begin),
            (troop_get_slot, ":var_4", ":var_3", slot_troop_current_mission),
            (troop_slot_eq, ":var_3", slot_troop_occupation, 5),
            (str_store_troop_name, s4, ":var_3"),
            (try_begin),
                (troop_slot_eq, ":var_3", slot_troop_mission_object, 1),
                (str_store_string, s8, "str_gathering_support"),
                (try_begin),
                    (eq, ":var_4", 1),
                    (str_store_string, s5, "str_expected_back_imminently"),
                (else_try),
                    (assign, reg3, ":var_4"),
                    (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
                (try_end),
            (else_try),
                (troop_slot_eq, ":var_3", slot_troop_mission_object, 2),
                (troop_get_slot, ":var_5", ":var_3", slot_troop_town_with_contacts),
                (str_store_party_name, s11, ":var_5"),
                (str_store_string, s8, "str_gathering_intelligence"),
                (try_begin),
                    (eq, ":var_4", 1),
                    (str_store_string, s5, "str_expected_back_imminently"),
                (else_try),
                    (assign, reg3, ":var_4"),
                    (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
                (try_end),
            (else_try),
                (troop_slot_eq, ":var_3", slot_troop_mission_object, 9),
                (str_store_string, s8, "@Training your Order troops."),
                (try_begin),
                    (eq, ":var_4", 1),
                    (str_store_string, s5, "str_expected_back_imminently"),
                (else_try),
                    (assign, reg3, ":var_4"),
                    (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
                (try_end),
            (else_try),
                (troop_slot_ge, ":var_3", slot_troop_mission_object, 3),
                (neg|troop_slot_ge, ":var_3", slot_troop_mission_object, 8),
                (troop_get_slot, ":var_6", ":var_3", slot_troop_recent_offense_time),
                (str_store_faction_name, s9, ":var_6"),
                (str_store_string, s8, "str_diplomatic_embassy_to_s9"),
                (try_begin),
                    (eq, ":var_4", 1),
                    (str_store_string, s5, "str_expected_back_imminently"),
                (else_try),
                    (assign, reg3, ":var_4"),
                    (str_store_string, s5, "str_expected_back_in_approximately_reg3_days"),
                (try_end),
            (else_try),
                (eq, ":var_3", "$g_player_minister"),
                (str_store_string, s8, "str_serving_as_minister"),
                (try_begin),
                    (is_between, "$g_player_court", "p_town_1", "p_salt_mine"),
                    (str_store_party_name, s9, "$g_player_court"),
                    (str_store_string, s5, "str_in_your_court_at_s9"),
                (else_try),
                    (str_store_string, s5, "str_whereabouts_unknown"),
                (try_end),
            (else_try),
                (main_party_has_troop, ":var_3"),
                (str_store_string, s8, "str_under_arms"),
                (str_store_string, s5, "str_in_your_party"),
            (else_try),
                (troop_slot_eq, ":var_3", slot_troop_mission_object, 8),
                (str_store_string, s8, "str_attempting_to_rejoin_party"),
                (str_store_string, s5, "str_whereabouts_unknown"),
            (else_try),
                (troop_slot_ge, ":var_3", slot_troop_cur_center, 1),
                (str_store_string, s8, "str_separated_from_party"),
                (str_store_string, s5, "str_whereabouts_unknown"),
            (else_try),
                (try_begin),
                    (check_quest_active, "qst_lend_companion"),
                    (quest_slot_eq, "qst_lend_companion", 2, ":var_3"),
                    (str_store_string, s8, "@On loan,"),
                (else_try),
                    (troop_set_slot, ":var_3", slot_troop_mission_object, 8),
                    (str_store_string, s8, "str_attempting_to_rejoin_party"),
                (try_end),
                (str_store_string, s5, "str_whereabouts_unknown"),
                (try_begin),
                    (ge, "$cheat_mode", 1),
                    (troop_get_slot, reg2, ":var_3", slot_troop_mission_object),
                    (troop_get_slot, reg3, ":var_3", slot_troop_current_mission),
                    (troop_get_slot, reg4, ":var_3", slot_troop_prisoner_of_party),
                    (troop_get_slot, reg4, ":var_3", slot_troop_playerparty_history),
                    (display_message, "@{!}DEBUG: {s4} current mission: {reg2}, days on mission: {reg3}, prisoner: {reg4}, pphistory: {reg5}"),
                (try_end),
            (try_end),
            (str_store_string, s3, "str_s4_s8_s5"),
            (str_store_string, s2, 1),
            (str_store_string, s1, "str_s2_s3"),
            (str_clear, s7),
        (else_try),
            (neg|troop_slot_eq, ":var_3", slot_troop_occupation, 2),
            (troop_slot_ge, ":var_3", slot_troop_prisoner_of_party, "p_town_1"),
            (str_store_troop_name, s4, ":var_3"),
            (str_store_string, s8, "str_missing_after_battle"),
            (str_store_string, s5, "str_whereabouts_unknown"),
            (str_store_string, s3, "str_s4_s8_s5"),
            (str_store_string, s2, 1),
            (str_store_string, s1, "str_s2_s3"),
            (str_clear, s7),
        (try_end),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("faction_orders", 0,
"{!}{s9}",
"none", 
[
    (str_clear, s9),
    (store_current_hours, ":var_0"),
    (try_for_range, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (faction_slot_eq, ":var_1", slot_faction_state, 0),
        (neg|eq, ":var_1", "fac_player_supporters_faction"),
        (faction_get_slot, ":var_2", ":var_1", slot_faction_ai_state),
        (try_begin),
            (faction_get_slot, ":var_3", ":var_1", slot_faction_marshall),
            (gt, ":var_3", -1),
            (assign, ":var_4", ":var_3"),
        (else_try),
            (faction_get_slot, ":var_4", ":var_1", slot_faction_leader),
        (try_end),
        (call_script, "script_npc_decision_checklist_faction_ai_alt", ":var_4"),
        (assign, ":var_5", reg0),
        (str_store_string, s26, 14),
        (faction_get_slot, ":var_6", ":var_1", slot_faction_ai_state),
        (faction_get_slot, ":var_7", ":var_1", slot_faction_ai_object),
        (faction_get_slot, ":var_8", ":var_1", slot_faction_marshall),
        (faction_get_slot, ":var_9", ":var_1", slot_faction_ai_offensive_max_followers),
        (str_store_faction_name, s10, ":var_1"),
        (try_begin),
            (faction_get_slot, ":var_10", ":var_1", slot_faction_political_issue),
            (try_begin),
                (eq, ":var_10", 1),
                (str_store_string, s11, "@Appoint next marshal"),
            (else_try),
                (is_between, ":var_10", "p_town_1", "p_salt_mine"),
                (str_store_party_name, s12, ":var_10"),
                (str_store_string, s11, "@Award {s12} as fief"),
            (else_try),
                (eq, ":var_10", 0),
                (str_store_string, s11, "@None"),
            (else_try),
                (assign, reg3, ":var_10"),
                (str_store_string, s11, "@{!}Error ({reg3})"),
            (try_end),
            (store_current_hours, reg4),
            (faction_get_slot, ":var_11", ":var_1", slot_faction_political_issue_time),
            (val_sub, reg4, ":var_11"),
            (str_store_string, s10, "@{!}{s10}^Faction political issue: {s11}"),
            (try_begin),
                (faction_slot_ge, ":var_1", slot_faction_political_issue, 1),
                (str_store_string, s10, "@{!}{s10} (on agenda {reg4} hours)"),
            (try_end),
        (try_end),
        (assign, reg2, ":var_9"),
        (try_begin),
            (eq, ":var_6", 0),
            (str_store_string, s11, "@{!}Defending"),
        (else_try),
            (eq, ":var_6", 1),
            (str_store_string, s11, "@{!}Gathering army"),
        (else_try),
            (eq, ":var_6", 2),
            (str_store_party_name, s11, ":var_7"),
            (str_store_string, s11, "@{!}Besieging {s11}"),
        (else_try),
            (eq, ":var_6", 3),
            (str_store_party_name, s11, ":var_7"),
            (str_store_string, s11, "@{!}Raiding {s11}"),
        (else_try),
            (eq, ":var_6", 4),
            (str_store_party_name, s11, ":var_7"),
            (str_store_string, s11, "str_attacking_enemy_army_near_s11"),
        (else_try),
            (eq, ":var_6", 6),
            (str_store_party_name, s11, ":var_7"),
            (str_store_string, s11, "str_holding_feast_at_s11"),
        (else_try),
            (eq, ":var_6", 5),
            (str_store_party_name, s11, ":var_7"),
            (str_store_string, s11, "@{!}Attacking enemies around {s11}"),
        (else_try),
            (assign, reg4, ":var_6"),
            (str_store_string, s11, "str_sfai_reg4"),
        (try_end),
        (try_begin),
            (neg|ge, ":var_8", 0),
            (str_store_string, s12, "@No one"),
        (else_try),
            (str_store_troop_name, s12, ":var_8"),
            (troop_get_slot, reg21, ":var_8", slot_troop_days_on_mission),
            (str_store_string, s12, "@{!}{s12} (controversy: {reg21})"),
        (try_end),
        (try_for_parties, ":var_12"),
            (party_slot_eq, ":var_12", slot_party_ai_state, 12),
            (store_faction_of_party, ":var_13", ":var_12"),
            (eq, ":var_13", ":var_1"),
            (str_store_party_name, s38, ":var_12"),
            (str_store_string, s12, "@{!}{s12}^Screening party: {s38}"),
        (try_end),
        (try_begin),
            (this_or_next|eq, ":var_5", 0),
            (eq, ":var_5", 6),
            (store_current_hours, ":var_14"),
            (faction_get_slot, ":var_15", ":var_1", slot_faction_ai_current_state_started),
            (val_sub, ":var_14", ":var_15"),
            (ge, ":var_14", 18),
            (store_current_hours, ":var_16"),
            (faction_set_slot, ":var_1", slot_faction_ai_last_rest_time, ":var_16"),
        (try_end),
        (try_begin),
            (neg|eq, ":var_5", ":var_2"),
            (store_current_hours, ":var_16"),
            (faction_set_slot, ":var_1", slot_faction_ai_current_state_started, ":var_16"),
        (try_end),
        (call_script, "script_evaluate_realm_stability", ":var_1"),
        (assign, ":var_17", reg0),
        (assign, ":var_18", reg1),
        (faction_get_slot, ":var_19", ":var_1", slot_faction_last_feast_concluded),
        (store_sub, ":var_20", ":var_0", ":var_19"),
        (val_sub, ":var_20", 72),
        (faction_get_slot, ":var_15", ":var_1", slot_faction_ai_current_state_started),
        (store_sub, ":var_14", ":var_0", ":var_15"),
        (faction_get_slot, ":var_21", ":var_1", slot_faction_ai_last_offensive_time),
        (store_sub, ":var_22", ":var_0", ":var_21"),
        (faction_get_slot, ":var_23", ":var_1", slot_faction_ai_last_rest_time),
        (store_sub, ":var_24", ":var_0", ":var_23"),
        (faction_get_slot, ":var_25", ":var_1", slot_faction_ai_last_decisive_event),
        (store_sub, ":var_26", ":var_0", ":var_25"),
        (assign, reg3, ":var_14"),
        (assign, reg4, ":var_22"),
        (assign, reg5, ":var_20"),
        (assign, reg7, ":var_17"),
        (assign, reg8, ":var_18"),
        (assign, reg9, ":var_24"),
        (assign, reg10, ":var_26"),
        (str_store_string, s14, 26),
        (str_store_string, s9, "str_s9s10_current_state_s11_hours_at_current_state_reg3_current_strategic_thinking_s14_marshall_s12_since_the_last_offensive_ended_reg4_hours_since_the_decisive_event_reg10_hours_since_the_last_rest_reg9_hours_since_the_last_feast_ended_reg5_hours_percent_disgruntled_lords_reg7_percent_restless_lords_reg8__"),
    (try_end),
    (try_begin),
        (neg|is_between, "$g_cheat_selected_faction", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (call_script, "script_get_next_active_kingdom", "fac_kingdoms_end"),
        (assign, "$g_cheat_selected_faction", reg0),
    (try_end),
    (str_store_faction_name, s10, "$g_cheat_selected_faction"),
    (str_store_string, s9, "@Selected faction is: {s10}^^{s9}"),
],
[
    ("faction_orders_next_faction", [],
    "{!}Select next faction.",
    [
        (call_script, "script_get_next_active_kingdom", "$g_cheat_selected_faction"),
        (assign, "$g_cheat_selected_faction", reg0),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("faction_orders_political_collapse", [],
    "{!}CHEAT - Cause all lords in faction to fall out with their liege.",
    [
        (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
            (store_troop_faction, ":var_1", ":var_0"),
            (eq, ":var_1", "$g_cheat_selected_faction"),
            (faction_get_slot, ":var_2", ":var_1", slot_faction_leader),
            (call_script, "script_troop_change_relation_with_troop", ":var_0", ":var_2", -200),
        (try_end),
    ], "."),

    ("faction_orders_defend", [],
    "{!}Force defend.",
    [
        (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_state, 0),
        (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_object, -1),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("faction_orders_feast", [],
    "{!}Force feast.",
    [
        (assign, ":var_0", 0),
        (try_for_range, ":var_1", "p_town_1", "p_village_1"),
            (neg|party_slot_ge, ":var_1", slot_center_is_besieged_by, 1),
            (store_faction_of_party, ":var_2", ":var_1"),
            (eq, ":var_2", "$g_cheat_selected_faction"),
            (party_get_slot, ":var_3", ":var_1", slot_town_lord),
            (troop_get_slot, ":var_4", ":var_3", slot_troop_renown),
            (store_random_in_range, ":var_5", 0, 1000),
            (val_add, ":var_4", ":var_5"),
            (gt, ":var_4", ":var_0"),
            (assign, ":var_0", ":var_4"),
            (assign, ":var_6", ":var_1"),
        (try_end),
        (try_begin),
            (gt, ":var_6", "p_town_1"),
            (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_state, 6),
            (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_object, ":var_6"),
            (try_begin),
                (eq, "$g_player_eligible_feast_center_no", ":var_6"),
                (assign, "$g_player_eligible_feast_center_no", -1),
            (try_end),
            (store_current_hours, ":var_7"),
            (faction_set_slot, "$g_cheat_selected_faction", slot_faction_last_feast_concluded, ":var_7"),
        (try_end),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("faction_orders_gather", [],
    "{!}Force gather army.",
    [
        (store_current_hours, ":var_0"),
        (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_state, 1),
        (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_last_offensive_time, ":var_0"),
        (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_offensive_max_followers, 1),
        (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_object, -1),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("faction_orders_increase_time", [],
    "{!}Increase last offensive time by 24 hours.",
    [
        (faction_get_slot, ":var_0", "$g_cheat_selected_faction", slot_faction_ai_last_offensive_time),
        (val_sub, ":var_0", 24),
        (faction_set_slot, "$g_cheat_selected_faction", slot_faction_ai_last_offensive_time, ":var_0"),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("faction_orders_rethink", [],
    "{!}Force rethink.",
    [
        (call_script, "script_init_ai_calculation"),
        (call_script, "script_decide_faction_ai", "$g_cheat_selected_faction"),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("faction_orders_rethink_all", [],
    "{!}Force rethink for all factions.",
    [
        (call_script, "script_recalculate_ais"),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("enable_alt_ai", 
    [
        (eq, "$g_use_alternative_ai", 2),
    ],
    "{!}CHEAT! - enable alternative ai",
    [
        (assign, "$g_use_alternative_ai", 1),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("disable_alt_ai", 
    [
        (eq, "$g_use_alternative_ai", 2),
    ],
    "{!}CHEAT! - disable alternative ai",
    [
        (assign, "$g_use_alternative_ai", 0),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("faction_orders_init_econ", [],
    "{!}Initialize economic stats.",
    [
        (call_script, "script_initialize_economic_information"),
        (jump_to_menu, "mnu_faction_orders"),
    ], "."),

    ("go_back_dot", [],
    "{!}Go back.",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("character_report", 0,
"{s9}",
"none", 
[
    (try_begin),
        (gt, "$g_player_reading_book", 0),
        (player_has_item, "$g_player_reading_book"),
        (str_store_item_name, s8, "$g_player_reading_book"),
        (str_store_string, s9, "@You are currently reading {s8}."),
    (else_try),
        (assign, "$g_player_reading_book", 0),
        (str_store_string, s9, "@You are not reading any books."),
    (try_end),
    (assign, ":var_0", 0),
    (assign, ":var_1", 0),
    (str_store_string, s6, "@none"),
    (str_store_string, s8, "@none"),
    (try_for_range, ":var_2", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (this_or_next|troop_slot_eq, ":var_2", slot_troop_occupation, 2),
        (troop_slot_eq, ":var_2", slot_troop_occupation, 9),
        (call_script, "script_troop_get_player_relation", ":var_2"),
        (assign, ":var_3", reg0),
        (try_begin),
            (gt, ":var_3", 20),
            (try_begin),
                (eq, ":var_0", 0),
                (str_store_troop_name, s8, ":var_2"),
            (else_try),
                (eq, ":var_0", 1),
                (str_store_troop_name, s7, ":var_2"),
                (str_store_string, s8, "@{s7} and {s8}"),
            (else_try),
                (str_store_troop_name, s7, ":var_2"),
                (str_store_string, s8, "@{!}{s7}, {s8}"),
            (try_end),
            (val_add, ":var_0", 1),
        (else_try),
            (neg|ge, ":var_3", -20),
            (try_begin),
                (eq, ":var_1", 0),
                (str_store_troop_name, s6, ":var_2"),
            (else_try),
                (eq, ":var_1", 1),
                (str_store_troop_name, s5, ":var_2"),
                (str_store_string, s6, "@{s5} and {s6}"),
            (else_try),
                (str_store_troop_name, s5, ":var_2"),
                (str_store_string, s6, "@{!}{s5}, {s6}"),
            (try_end),
            (val_add, ":var_1", 1),
        (try_end),
    (try_end),
    (str_clear, s12),
    (try_begin),
        (gt, "$player_right_to_rule", 0),
        (assign, reg12, "$player_right_to_rule"),
        (str_store_string, s12, "str__right_to_rule_reg12"),
    (try_end),
    (str_clear, s15),
    (try_begin),
        (this_or_next|gt, "$claim_arguments_made", 0),
        (this_or_next|gt, "$ruler_arguments_made", 0),
        (this_or_next|gt, "$victory_arguments_made", 0),
        (this_or_next|gt, "$lords_arguments_made", 0),
        (eq, 1, 0),
        (assign, reg3, "$claim_arguments_made"),
        (assign, reg4, "$ruler_arguments_made"),
        (assign, reg5, "$victory_arguments_made"),
        (assign, reg6, "$lords_arguments_made"),
        (assign, reg7, "$benefit_arguments_made"),
        (str_store_string, s15, "str_political_arguments_made_legality_reg3_rights_of_lords_reg4_unificationpeace_reg5_rights_of_commons_reg6_fief_pledges_reg7"),
    (try_end),
    (assign, reg3, "$player_honor"),
    (troop_get_slot, reg2, "trp_player", slot_troop_renown),
    (str_store_string, s9, "str_renown_reg2_honour_rating_reg3s12_friends_s8_enemies_s6_s9"),
    (call_script, "script_get_number_of_hero_centers", "trp_player"),
    (assign, ":var_4", reg0),
    (try_begin),
        (gt, ":var_4", 0),
        (try_for_range_backwards, ":var_5", 0, ":var_4"),
            (call_script, "script_troop_get_leaded_center_with_index", "trp_player", ":var_5"),
            (assign, ":var_6", reg0),
            (store_sub, ":var_7", ":var_4", ":var_5"),
            (val_sub, ":var_7", 1),
            (try_begin),
                (eq, ":var_7", 0),
                (str_store_party_name, s8, ":var_6"),
            (else_try),
                (eq, ":var_7", 1),
                (str_store_party_name, s7, ":var_6"),
                (str_store_string, s8, "@{s7} and {s8}"),
            (else_try),
                (str_store_party_name, s7, ":var_6"),
                (str_store_string, s8, "@{!}{s7}, {s8}"),
            (try_end),
        (try_end),
        (str_store_string, s9, "@Your estates are: {s8}.^{s9}"),
    (try_end),
    (try_begin),
        (troop_get_slot, ":var_8", "trp_player", 162),
        (neg|eq, ":var_8", 0),
        (store_troop_faction, ":var_9", ":var_8"),
        (faction_get_slot, ":var_10", ":var_9", 72),
        (store_sub, ":var_11", ":var_10", 1),
        (val_add, ":var_11", "str_order_rank_1"),
        (str_store_string, s8, ":var_11"),
        (try_begin),
            (eq, ":var_9", "fac_player_knights"),
            (str_store_string, s8, "@Honorary Grandmaster"),
        (else_try),
            (neg|ge, ":var_10", 7),
            (faction_get_slot, reg1, ":var_9", 71),
            (str_store_string, s8, "@{s8} ({reg1})"),
        (try_end),
        (str_store_faction_name, s12, ":var_9"),
        (str_store_string, s9, "@You are a {s8} of the Order of the {s12}.^{s9}"),
    (try_end),
    (assign, reg1, 0),
    (try_begin),
        (faction_slot_ge, "fac_player_faction", 70, 1),
        (faction_get_slot, ":var_12", "fac_player_faction", 70),
        (assign, reg1, ":var_12"),
    (try_end),
    (try_begin),
        (eq, "$pop_kingdom", 1),
        (str_store_faction_name, s8, "$players_kingdom"),
        (faction_get_slot, ":var_13", "fac_player_supporters_faction", slot_faction_culture),
        (str_store_faction_name, s7, ":var_13"),
        (call_script, "script_gender_to_reg63"),
        (str_store_string, s9, "@You are the sovereign {reg63?King:Queen} of the {s8}, embracing the culture of {s7}.^{s9} ^ You have {reg1} Noble Recruits."),
    (else_try),
        (gt, "$players_kingdom", 0),
        (str_store_faction_name, s8, "$players_kingdom"),
        (try_begin),
            (eq, "$player_has_homage", 1),
            (str_store_string, s9, "@You are a lord of the {s8}.^{s9} ^ You have {reg1} Noble Recruits."),
        (else_try),
            (faction_slot_eq, "$players_kingdom", slot_faction_leader, "trp_player"),
            (str_store_string, s9, "@You are a Rogue Leader of the {s8}.^{s9}"),
        (else_try),
            (str_store_string, s9, "@You are a Mercenary Captain in the service of the {s8}.^{s9}"),
        (try_end),
    (else_try),
        (str_store_string, s9, "@You are a Mercenary Captain. ^ {s9}"),
    (try_end),
],
[
    ("continue", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! - increase Right to Rule",
    [
        (val_add, "$player_right_to_rule", 10),
        (jump_to_menu, "mnu_character_report"),
    ], "."),

    ("continue", 
    [
        (eq, "$cheat_mode", 1),
        (str_store_troop_name, s14, "$g_talk_troop"),
    ],
    "{!}CHEAT! - increase your relation with {s14}",
    [
        (call_script, "script_change_player_relation_with_troop", "$g_talk_troop", 10),
        (jump_to_menu, "mnu_character_report"),
    ], "."),

    ("continue", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! - increase honor",
    [
        (val_add, "$player_honor", 10),
        (jump_to_menu, "mnu_character_report"),
    ], "."),

    ("continue", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! - increase renown",
    [
        (troop_get_slot, ":var_0", "trp_player", slot_troop_renown),
        (val_add, ":var_0", 50),
        (troop_set_slot, "trp_player", slot_troop_renown, ":var_0"),
        (jump_to_menu, "mnu_character_report"),
    ], "."),

    ("continue", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! - increase persuasion",
    [
        (troop_raise_skill, "trp_player", "skl_persuasion", 1),
        (jump_to_menu, "mnu_character_report"),
    ], "."),

    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("party_size_report", 0,
"{s1}",
"none", 
[
    (call_script, "script_game_get_party_companion_limit"),
    (assign, ":var_0", reg0),
    (store_skill_level, ":var_1", "skl_leadership", "trp_player"),
    (val_mul, ":var_1", 10),
    (store_attribute_level, ":var_2", "trp_player", ca_charisma),
    (troop_get_slot, ":var_3", "trp_player", slot_troop_renown),
    (val_div, ":var_3", 25),
    (try_begin),
        (gt, ":var_1", 0),
        (str_store_string, s2, "@{!} +"),
    (else_try),
        (str_store_string, s2, "str_space"),
    (try_end),
    (try_begin),
        (gt, ":var_2", 0),
        (val_mul, ":var_2", 2),
        (str_store_string, s3, "@{!} +"),
    (else_try),
        (str_store_string, s3, "str_space"),
    (try_end),
    (try_begin),
        (gt, ":var_3", 0),
        (str_store_string, s4, "@{!} +"),
    (else_try),
        (str_store_string, s4, "str_space"),
    (try_end),
    (assign, reg5, ":var_0"),
    (assign, reg1, ":var_1"),
    (assign, reg2, ":var_2"),
    (assign, reg3, ":var_3"),
    (str_store_string, s1, "@Current party size limit is {reg5}.^Current party size modifiers are:^^Base size:  +30^Leadership: {s2}{reg1}^Charisma: {s3}{reg2}^Renown: {s4}{reg3}^TOTAL:  {reg5}"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("faction_relations_report", 0,
"{s1}",
"none", 
[
    (str_clear, s2),
    (try_for_range, ":var_0", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (faction_slot_eq, ":var_0", slot_faction_state, 0),
        (neg|eq, ":var_0", "fac_player_supporters_faction"),
        (store_relation, ":var_1", "fac_player_supporters_faction", ":var_0"),
        (call_script, "script_faction_relations_text_reporter", ":var_1"),
        (str_store_faction_name, s4, ":var_0"),
        (assign, reg1, ":var_1"),
        (str_store_string, s2, "@{s2}^The {s4}: {reg1} ({s33})"),
    (try_end),
    (str_store_string, s2, "@{s2}^"),
    (try_for_range, ":var_0", "fac_noldor_elves", "fac_dragon_knights"),
        (store_relation, ":var_1", "fac_player_faction", ":var_0"),
        (call_script, "script_faction_relations_text_reporter", ":var_1"),
        (str_store_faction_name, s4, ":var_0"),
        (assign, reg1, ":var_1"),
        (try_begin),
            (is_between, ":var_0", "fac_barclay", "fac_jatu"),
            (str_store_string, s2, "@{s2}^{s4}: {reg1} ({s33})"),
        (else_try),
            (str_store_string, s2, "@{s2}^The {s4}: {reg1} ({s33})"),
        (try_end),
    (try_end),
    (str_store_string, s1, "@Your relations with the factions are:^{s2}"),
],
[
    ("orders", [],
    "View relations with Knighthood Orders.",
    [
        (jump_to_menu, "mnu_order_relations_report"),
    ], "."),

    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("order_relations_report", 0,
"{s1}",
"none", 
[
    (str_clear, s2),
    (try_for_range, ":var_0", "fac_dragon_knights", "fac_noldor_castle"),
        (this_or_next|neg|eq, ":var_0", "fac_player_knights"),
        (eq, "$players_order_name_set", 1),
        (store_relation, ":var_1", "fac_player_supporters_faction", ":var_0"),
        (call_script, "script_faction_relations_text_reporter", ":var_1"),
        (str_store_faction_name, s4, ":var_0"),
        (assign, reg1, ":var_1"),
        (str_store_string, s2, "@{s2}^The {s4}: {reg1} ({s33})"),
    (try_end),
    (str_store_string, s1, "@Your relations with the Orders are:^{s2}"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_reports"),
    ], "."),

]),

("camp", 4096,
"You set up camp. What do you want to do?",
"none", 
[
    (assign, "$g_player_icon_state", 0),
    (set_background_mesh, "mesh_pic_camp"),
],
[
    ("camp_action_1", [],
    "Walk around and review your soldiers.",
    [
        (set_jump_mission, "mt_ai_training_with_formations"),
        (call_script, "script_setup_random_scene"),
        (assign, "$g_encountered_party", -1),
        (change_screen_mission),
    ], "."),

    ("camp_manage_inventory", 
    [
        (call_script, "script_get_count_of_companions"),
        (gt, reg0, 0),
    ],
    "Manage your party's inventory.",
    [
        (troop_clear_inventory, "trp_temp_troop"),
        (assign, "$return_menu", "mnu_camp"),
        (assign, "$inventory_menu_offset", 0),
        (str_clear, s30),
        (jump_to_menu, "mnu_manage_loot_pool"),
    ], "."),

    ("camp_action", [],
    "Take an action.",
    [
        (jump_to_menu, "mnu_camp_action"),
    ], "."),

    ("camp_wait_here", [],
    "Wait here for some time.",
    [
        (assign, "$g_camp_mode", 1),
        (assign, "$g_infinite_camping", 0),
        (assign, "$g_player_icon_state", 1),
        (try_begin),
            (party_is_active, "p_main_party"),
            (party_get_current_terrain, ":var_0", "p_main_party"),
            (try_begin),
                (eq, ":var_0", 5),
                (unlock_achievement, 28),
            (try_end),
        (try_end),
        (rest_for_hours_interactive, 8760, 5, 1),
        (change_screen_return),
    ], "."),

    ("camp_cheat", 
    [
        (ge, "$cheat_mode", 1),
    ],
    "CHEAT MENU!",
    [
        (jump_to_menu, "mnu_camp_cheat"),
    ], "."),

    ("camp_options", [],
    "Change POP game options.",
    [
        (jump_to_menu, "mnu_game_options"),
    ], "."),

    ("check_loot", [],
    "Check the loot",
    [
        (troop_get_slot, ":var_0", "trp_loot_pool", 188),
        (troop_get_slot, ":var_1", "trp_loot_pool", 189),
        (try_begin),
            (gt, ":var_0", 0),
            (ge, ":var_0", ":var_1"),
            (change_screen_loot, "trp_loot_pool"),
        (else_try),
            (jump_to_menu, "mnu_manage_loot"),
        (try_end),
    ], "."),

    ("test_vader", 
    [
        (neg|eq, "$cheat_mode", 0),
    ],
    "MV Test Menu",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

    ("resume_travelling", [],
    "Resume travelling.",
    [
        (try_begin),
            (neg|eq, "$g_option_companion_dialogs", 0),
            (store_random_in_range, ":var_0", 0, 100),
            (neg|ge, ":var_0", 5),
            (assign, ":var_1", 0),
            (assign, ":var_2", 0),
            (try_for_range, ":var_3", "trp_npc_adonja", "trp_kingdom_1_lord"),
                (main_party_has_troop, ":var_3"),
                (neg|troop_is_wounded, ":var_3"),
                (troop_get_slot, ":var_4", ":var_3", 79),
                (store_and, ":var_2", ":var_4", 8),
                (eq, ":var_2", 0),
                (assign, ":var_5", 0),
                (try_begin),
                    (eq, ":var_3", "trp_npc_adonja"),
                    (neg|main_party_has_troop, "trp_npc_ansen"),
                (else_try),
                    (eq, ":var_3", "trp_npc_ediz"),
                    (neg|main_party_has_troop, "trp_npc_rayne"),
                (else_try),
                    (eq, ":var_3", "trp_npc_jocelyn"),
                    (neg|main_party_has_troop, "trp_npc_alistair"),
                (else_try),
                    (eq, ":var_3", "trp_npc_rayne"),
                    (neg|main_party_has_troop, "trp_npc_boadice"),
                (else_try),
                    (eq, ":var_3", "trp_npc_riva"),
                    (neg|main_party_has_troop, "trp_npc_kassim"),
                (else_try),
                    (eq, ":var_3", "trp_npc_leslie"),
                    (neg|main_party_has_troop, "trp_npc_diev"),
                (else_try),
                    (eq, ":var_3", "trp_npc_diev"),
                    (neg|main_party_has_troop, "trp_npc_leslie"),
                (else_try),
                    (assign, ":var_5", 1),
                (try_end),
                (eq, ":var_5", 1),
                (val_add, ":var_1", 1),
            (try_end),
            (gt, ":var_1", 0),
            (assign, ":var_6", -1),
            (store_random_in_range, ":var_7", 0, ":var_1"),
            (try_for_range, ":var_3", "trp_npc_adonja", "trp_kingdom_1_lord"),
                (ge, ":var_7", 0),
                (main_party_has_troop, ":var_3"),
                (neg|troop_is_wounded, ":var_3"),
                (troop_get_slot, ":var_4", ":var_3", 79),
                (store_and, ":var_2", ":var_4", 8),
                (eq, ":var_2", 0),
                (assign, ":var_5", 0),
                (try_begin),
                    (eq, ":var_3", "trp_npc_adonja"),
                    (neg|main_party_has_troop, "trp_npc_ansen"),
                (else_try),
                    (eq, ":var_3", "trp_npc_ediz"),
                    (neg|main_party_has_troop, "trp_npc_rayne"),
                (else_try),
                    (eq, ":var_3", "trp_npc_jocelyn"),
                    (neg|main_party_has_troop, "trp_npc_alistair"),
                (else_try),
                    (eq, ":var_3", "trp_npc_rayne"),
                    (neg|main_party_has_troop, "trp_npc_boadice"),
                (else_try),
                    (eq, ":var_3", "trp_npc_riva"),
                    (neg|main_party_has_troop, "trp_npc_kassim"),
                (else_try),
                    (eq, ":var_3", "trp_npc_leslie"),
                    (neg|main_party_has_troop, "trp_npc_diev"),
                (else_try),
                    (eq, ":var_3", "trp_npc_diev"),
                    (neg|main_party_has_troop, "trp_npc_leslie"),
                (else_try),
                    (assign, ":var_5", 1),
                (try_end),
                (eq, ":var_5", 1),
                (try_begin),
                    (eq, ":var_7", 0),
                    (val_or, ":var_4", 8),
                    (troop_set_slot, ":var_3", 79, ":var_4"),
                    (assign, ":var_6", ":var_3"),
                (try_end),
                (val_sub, ":var_7", 1),
            (try_end),
            (assign, "$npc_dialog_partner", -1),
            (start_map_conversation, ":var_6"),
            (change_screen_map),
        (else_try),
            (change_screen_return),
        (try_end),
    ], "."),

]),

("camp_cheat", 0,
"Select a cheat:",
"none", [],
[
    ("camp_cheat_find_item", [],
    "Find an item...",
    [
        (jump_to_menu, "mnu_cheat_find_item"),
    ], "."),

    ("camp_cheat_find_item", [],
    "Change weather..",
    [
        (jump_to_menu, "mnu_cheat_change_weather"),
    ], "."),

    ("camp_cheat_1", [],
    "{!}Increase player renown.",
    [
        (str_store_string, s1, "@Player renown is increased by 100. "),
        (call_script, "script_change_troop_renown", "trp_player", 100),
        (jump_to_menu, "mnu_camp_cheat"),
    ], "."),

    ("camp_cheat_2", [],
    "{!}Increase player honor.",
    [
        (assign, reg7, "$player_honor"),
        (val_add, reg7, 1),
        (display_message, "@Player honor is increased by 1 and it is now {reg7}."),
        (val_add, "$player_honor", 1),
        (jump_to_menu, "mnu_camp_cheat"),
    ], "."),

    ("camp_cheat_3", [],
    "{!}Update political notes.",
    [
        (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
            (call_script, "script_update_troop_political_notes", ":var_0"),
        (try_end),
        (try_for_range, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (call_script, "script_update_faction_political_notes", ":var_1"),
        (try_end),
    ], "."),

    ("camp_cheat_4", [],
    "{!}Update troop notes.",
    [
        (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
            (call_script, "script_update_troop_notes", ":var_0"),
        (try_end),
        (try_for_range, ":var_1", "trp_knight_1_1_wife", "trp_heroes_end"),
            (call_script, "script_update_troop_notes", ":var_1"),
            (call_script, "script_update_troop_political_notes", ":var_1"),
            (call_script, "script_update_troop_location_notes", ":var_1", 0),
        (try_end),
    ], "."),

    ("camp_cheat_5", [],
    "{!}Scramble minstrels.",
    [
        (call_script, "script_update_tavern_minstrels"),
    ], "."),

    ("camp_cheat_6", [],
    "{!}Infinite camp",
    [
        (assign, "$g_camp_mode", 1),
        (assign, "$g_infinite_camping", 1),
        (assign, "$g_player_icon_state", 1),
        (rest_for_hours_interactive, 87600, 20),
        (change_screen_return),
    ], "."),

    ("cheat_faction_orders", 
    [
        (ge, "$cheat_mode", 1),
    ],
    "{!}Cheat: Set Debug messages to All.",
    [
        (assign, "$cheat_mode", 1),
        (jump_to_menu, "mnu_camp_cheat"),
    ], "."),

    ("cheat_faction_orders", 
    [
        (ge, "$cheat_mode", 1),
        (neg|eq, "$cheat_mode", 3),
    ],
    "{!}Cheat: Set Debug messages to Econ Only.",
    [
        (assign, "$cheat_mode", 3),
        (jump_to_menu, "mnu_camp_cheat"),
    ], "."),

    ("cheat_faction_orders", 
    [
        (ge, "$cheat_mode", 1),
        (neg|eq, "$cheat_mode", 4),
    ],
    "{!}Cheat: Set Debug messages to Political Only.",
    [
        (assign, "$cheat_mode", 4),
        (jump_to_menu, "mnu_camp_cheat"),
    ], "."),

    ("back_to_camp_menu", [],
    "{!}Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("cheat_find_item", 0,
"{!}Current item range: {reg5} to {reg6}",
"none", 
[
    (assign, reg5, "$cheat_find_item_range_begin"),
    (store_add, reg6, "$cheat_find_item_range_begin", 96),
    (val_min, reg6, "itm_items_end"),
    (val_sub, reg6, 1),
],
[
    ("cheat_find_item_next_range", [],
    "{!}Move to next item range.",
    [
        (val_add, "$cheat_find_item_range_begin", 96),
        (try_begin),
            (ge, "$cheat_find_item_range_begin", "itm_items_end"),
            (assign, "$cheat_find_item_range_begin", 0),
        (try_end),
        (jump_to_menu, "mnu_cheat_find_item"),
    ], "."),

    ("cheat_find_item_choose_this", [],
    "{!}Choose from this range.",
    [
        (troop_clear_inventory, "trp_find_item_cheat"),
        (store_add, ":var_0", "$cheat_find_item_range_begin", 96),
        (val_min, ":var_0", "itm_items_end"),
        (store_sub, ":var_1", ":var_0", "$cheat_find_item_range_begin"),
        (try_for_range, ":var_2", 0, ":var_1"),
            (store_add, ":var_3", "$cheat_find_item_range_begin", ":var_2"),
            (troop_add_items, "trp_find_item_cheat", ":var_3", 1),
        (try_end),
        (change_screen_trade, "trp_find_item_cheat"),
    ], "."),

    ("camp_action_4", [],
    "{!}Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("cheat_change_weather", 0,
"{!}Current cloud amount: {reg5}^Current Fog Strength: {reg6}",
"none", 
[
    (get_global_cloud_amount, reg5),
    (get_global_haze_amount, reg6),
],
[
    ("cheat_increase_cloud", [],
    "{!}Increase Cloud Amount.",
    [
        (get_global_cloud_amount, ":var_0"),
        (val_add, ":var_0", 5),
        (val_min, ":var_0", 100),
        (set_global_cloud_amount, ":var_0"),
    ], "."),

    ("cheat_decrease_cloud", [],
    "{!}Decrease Cloud Amount.",
    [
        (get_global_cloud_amount, ":var_0"),
        (val_sub, ":var_0", 5),
        (val_max, ":var_0", 0),
        (set_global_cloud_amount, ":var_0"),
    ], "."),

    ("cheat_increase_fog", [],
    "{!}Increase Fog Amount.",
    [
        (get_global_haze_amount, ":var_0"),
        (val_add, ":var_0", 5),
        (val_min, ":var_0", 100),
        (set_global_haze_amount, ":var_0"),
    ], "."),

    ("cheat_decrease_fog", [],
    "{!}Decrease Fog Amount.",
    [
        (get_global_haze_amount, ":var_0"),
        (val_sub, ":var_0", 5),
        (val_max, ":var_0", 0),
        (set_global_haze_amount, ":var_0"),
    ], "."),

    ("camp_action_4", [],
    "{!}Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("camp_vader", 0,
"What do you want to test today?",
"none", [],
[
    ("camp_vader_back", [],
    "Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

    ("camp_vader_ownorder", [],
    "Test Player Order...",
    [
        (jump_to_menu, "mnu_camp_ownorder"),
    ], "."),

    ("camp_vader_gmquest", [],
    "Setup Grandmaster quest.",
    [
        (call_script, "script_end_quest", "qst_order_grandmaster"),
        (quest_set_slot, "qst_order_grandmaster", 11, 0),
        (troop_get_slot, ":var_0", "trp_player", 162),
        (try_begin),
            (eq, ":var_0", 0),
            (troop_set_slot, "trp_player", 162, "trp_lion_knight"),
            (assign, ":var_0", "trp_lion_knight"),
        (try_end),
        (store_troop_faction, ":var_1", ":var_0"),
        (faction_set_slot, ":var_1", 72, 6),
        (faction_set_slot, ":var_1", 71, 300),
        (str_store_faction_name, s12, ":var_1"),
        (display_message, "@GM quest ready: talk to the {s12} for a surprise.", 0x30FFC8),
        (change_screen_map),
    ], "."),

    ("camp_vader_randorder", [],
    "Generate a random Order.",
    [
        (call_script, "script_generate_minor_order", "p_castle_24"),
        (assign, ":var_0", reg0),
        (faction_get_slot, ":var_1", ":var_0", 68),
        (party_add_members, "p_main_party", ":var_1", 10),
        (spawn_around_party, "p_main_party", "pt_errant_knights"),
        (party_set_faction, reg0, ":var_0"),
        (party_add_members, reg0, ":var_1", 10),
        (str_store_faction_name, s12, ":var_0"),
        (str_store_troop_name, s13, ":var_1"),
        (display_message, "@Random order of the {s12} created in Kennet Castle. 10 {s13}s recruited and party spawned.", 0x30FFC8),
        (change_screen_map),
    ], "."),

    ("camp_vader_renown", [],
    "Add 100 renown",
    [
        (call_script, "script_change_troop_renown", "trp_player", 100),
    ], "."),

    ("camp_vader_honor", [],
    "Add 10 honor.",
    [
        (call_script, "script_change_player_honor", 10),
    ], "."),

    ("camp_vader_pimp", [],
    "Pimp me up first!",
    [
        (call_script, "script_change_troop_renown", "trp_player", 500),
        (call_script, "script_change_player_honor", 50),
        (troop_raise_attribute, "trp_player", ca_strength, 20),
        (troop_raise_attribute, "trp_player", ca_agility, 20),
        (troop_raise_attribute, "trp_player", ca_intelligence, 20),
        (troop_raise_attribute, "trp_player", ca_charisma, 20),
        (troop_raise_proficiency_linear, "trp_player", wpt_one_handed_weapon, 500),
        (troop_raise_proficiency_linear, "trp_player", wpt_two_handed_weapon, 500),
        (troop_raise_proficiency_linear, "trp_player", wpt_polearm, 500),
        (troop_raise_proficiency_linear, "trp_player", wpt_archery, 500),
        (troop_raise_proficiency_linear, "trp_player", wpt_crossbow, 500),
        (troop_raise_proficiency_linear, "trp_player", wpt_throwing, 500),
        (troop_raise_skill, "trp_player", skl_ironflesh, 10),
        (troop_raise_skill, "trp_player", skl_power_strike, 10),
        (troop_raise_skill, "trp_player", skl_weapon_master, 10),
        (troop_raise_skill, "trp_player", skl_athletics, 10),
        (troop_raise_skill, "trp_player", skl_power_draw, 10),
        (troop_raise_skill, "trp_player", skl_riding, 10),
        (troop_raise_skill, "trp_player", skl_spotting, 10),
        (troop_raise_skill, "trp_player", skl_prisoner_management, 10),
        (troop_raise_skill, "trp_player", skl_tactics, 10),
        (troop_raise_skill, "trp_player", skl_inventory_management, 10),
        (troop_raise_skill, "trp_player", skl_wound_treatment, 10),
        (troop_raise_skill, "trp_player", skl_first_aid, 10),
        (troop_raise_skill, "trp_player", skl_pathfinding, 10),
        (troop_raise_skill, "trp_player", skl_leadership, 10),
        (troop_raise_skill, "trp_player", skl_engineer, 10),
        (troop_add_gold, "trp_player", 300000),
        (troop_set_health, "trp_player", 100),
        (troop_add_item, "trp_player", "itm_pop_melitine_armor"),
        (troop_add_item, "trp_player", "itm_pop_melitine_armor_regular"),
        (troop_add_item, "trp_player", "itm_pop_melitine_armor_plate"),
        (troop_add_item, "trp_player", "itm_pop_melitine_helmet"),
        (troop_add_item, "trp_player", "itm_pl_25"),
        (troop_add_item, "trp_player", "itm_pop_melitine_mask_bronze"),
        (troop_add_item, "trp_player", "itm_pop_melitine_greaves"),
        (troop_add_item, "trp_player", "itm_pop_melitine_plate_boots"),
        (troop_add_item, "trp_player", "itm_pop_melitine_hunter"),
        (troop_add_item, "trp_player", "itm_pop_melitine_arm_hunter"),
        (troop_add_item, "trp_player", "itm_pop_melitine_shield"),
        (troop_add_item, "trp_player", "itm_pop_melitine_lance"),
        (troop_add_item, "trp_player", "itm_pop_melitine_impaler"),
        (troop_add_item, "trp_player", "itm_pop_melitine_spear"),
        (troop_add_item, "trp_player", "itm_pop_melitine_sabre"),
        (troop_add_item, "trp_player", "itm_pop_melitine_bow"),
        (troop_add_item, "trp_player", "itm_pop_melitine_longbow"),
        (troop_add_item, "trp_player", "itm_pop_melitine_arrows"),
        (troop_add_item, "trp_player", "itm_pop_melitine_arrows2"),
        (troop_add_item, "trp_player", "itm_arbalest"),
        (troop_add_item, "trp_player", "itm_steel_bolts"),
        (troop_add_item, "trp_player", "itm_dshar_armored_hunter"),
        (troop_add_item, "trp_player", "itm_hourglass_gauntlets_black"),
        (troop_add_item, "trp_player", "itm_early_transitional_heraldic"),
        (display_message, "@You have been pimped up!", 0x30FFC8),
        (troop_equip_items, "trp_player"),
    ], "."),

    ("camp_vader_ht", [],
    "Give me Honor troops...",
    [
        (jump_to_menu, "mnu_camp_honor"),
    ], "."),

    ("camp_vader_ct", [],
    "Give me cool troops...",
    [
        (jump_to_menu, "mnu_camp_cool"),
    ], "."),

    ("camp_vader_rt", [],
    "Give me regular troops...",
    [
        (jump_to_menu, "mnu_camp_regular"),
    ], "."),

    ("camp_vader_mf", [],
    "Spawn a minor faction...",
    [
        (jump_to_menu, "mnu_camp_minor"),
    ], "."),

    ("camp_vader_sh", [],
    "Spawn a special hero...",
    [
        (jump_to_menu, "mnu_camp_hero"),
    ], "."),

    ("camp_vader_balance", [],
    "Balance parties...",
    [
        (jump_to_menu, "mnu_camp_balance"),
    ], "."),

    ("camp_vader_qgs", [],
    "I really need 3 Qualis Gems",
    [
        (troop_add_items, "trp_player", "itm_pop_qualis", 3),
        (display_message, "@Gems given."),
    ], "."),

    ("camp_vader_cheat", 
    [
        (try_begin),
            (eq, "$cheat_mode", 0),
            (str_store_string, s7, "@OFF"),
        (else_try),
            (eq, "$cheat_mode", 1),
            (str_store_string, s7, "@Standard"),
        (else_try),
            (eq, "$cheat_mode", 2),
            (str_store_string, s7, "@Special"),
        (else_try),
            (eq, "$cheat_mode", 3),
            (str_store_string, s7, "@Economy"),
        (else_try),
            (eq, "$cheat_mode", 4),
            (str_store_string, s7, "@Politics"),
        (else_try),
            (str_store_string, s7, "@ERROR"),
        (try_end),
    ],
    "Toggle Native cheat mode: {s7}",
    [
        (val_add, "$cheat_mode", 1),
        (try_begin),
            (eq, "$cheat_mode", 5),
            (assign, "$cheat_mode", 0),
        (try_end),
    ], "."),

    ("camp_wait", [],
    "Fast forward for 100 days",
    [
        (assign, "$g_camp_mode", 1),
        (assign, "$g_infinite_camping", 1),
        (assign, "$g_player_icon_state", 1),
        (rest_for_hours_interactive, 2400, 40),
        (change_screen_return),
    ], "."),

    ("camp_vader_comp", [],
    "Test companion conversations...",
    [
        (jump_to_menu, "mnu_camp_companion"),
    ], "."),

]),

("camp_ownorder", 0,
"Select an option:",
"none", [],
[
    ("join", [],
    "Join Sarleon and take over Avendor.",
    [
        (call_script, "script_player_join_faction", "fac_kingdom_1"),
        (call_script, "script_give_center_to_lord", "p_town_16", "trp_player", 0),
        (call_script, "script_update_troop_notes", "trp_player"),
        (assign, "$player_has_homage", 1),
        (assign, "$g_player_banner_granted", 1),
        (troop_add_items, "trp_player", "itm_pop_qualis", 3),
        (call_script, "script_change_player_honor", 100),
        (troop_add_gold, "trp_player", 20000),
    ], "."),

    ("join2", [],
    "Join Fierdsvain and take over Windholm.",
    [
        (call_script, "script_player_join_faction", "fac_kingdom_4"),
        (call_script, "script_give_center_to_lord", "p_town_12", "trp_player", 0),
        (call_script, "script_update_troop_notes", "trp_player"),
        (assign, "$player_has_homage", 1),
        (assign, "$g_player_banner_granted", 1),
        (troop_add_items, "trp_player", "itm_pop_qualis", 3),
        (call_script, "script_change_player_honor", 100),
        (troop_add_gold, "trp_player", 20000),
    ], "."),

    ("finish", [],
    "Finish current upgrades",
    [
        (try_begin),
            (gt, "$g_pop_upgrade_knight_days", 0),
            (assign, "$g_pop_upgrade_knight_days", 0),
            (troop_set_inventory_slot, "trp_player_knight", "$g_pop_upgrade_knight_slot", "$g_pop_upgrade_knight_item"),
            (troop_set_inventory_slot, "trp_player_knight_save", "$g_pop_upgrade_knight_slot", "$g_pop_upgrade_knight_item"),
            (str_store_item_name_plural, s11, "$g_pop_upgrade_knight_item"),
            (str_store_troop_name_plural, s12, "trp_player_knight"),
            (display_message, "@Your {s12} have acquired new {s11}!"),
        (try_end),
        (try_begin),
            (gt, "$g_pop_upgrade_squire_days", 0),
            (assign, "$g_pop_upgrade_squire_days", 0),
            (troop_set_inventory_slot, "trp_player_sergeant", "$g_pop_upgrade_squire_slot", "$g_pop_upgrade_squire_item"),
            (troop_set_inventory_slot, "trp_player_sergeant_save", "$g_pop_upgrade_squire_slot", "$g_pop_upgrade_squire_item"),
            (str_store_item_name_plural, s11, "$g_pop_upgrade_squire_item"),
            (str_store_troop_name_plural, s12, "trp_player_sergeant"),
            (display_message, "@Your {s12} have acquired new {s11}!"),
        (try_end),
    ], "."),

    ("give", [],
    "Give me Order Knights and Squires",
    [
        (party_add_members, "p_main_party", "trp_player_knight", 10),
        (party_add_members, "p_main_party", "trp_player_sergeant", 10),
        (display_message, "@10 Order Knights and 10 Order Squires joined the party"),
    ], "."),

    ("back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_balance", 0,
"Choose wisely:",
"none", [],
[
    ("lords", [],
    "Calculate lord strengths.",
    [
        (assign, ":var_0", 0),
        (assign, ":var_1", 0),
        (try_for_range, ":var_2", "fac_kingdom_1", "fac_kingdoms_end"),
            (store_sub, ":var_3", ":var_2", "fac_kingdom_1"),
            (val_mul, ":var_3", 20),
            (val_add, ":var_3", "trp_knight_1_1"),
            (store_add, ":var_4", ":var_3", 20),
            (assign, ":var_5", 0),
            (assign, ":var_6", 0),
            (try_for_range, ":var_7", ":var_3", ":var_4"),
                (troop_get_slot, ":var_8", ":var_7", slot_troop_leaded_party),
                (party_is_active, ":var_8"),
                (call_script, "script_party_calculate_strength", ":var_8", 0),
                (str_store_troop_name, s4, ":var_7"),
                (display_message, "@{s4}: {reg0}"),
                (val_add, ":var_5", reg0),
                (val_add, ":var_6", 1),
            (try_end),
            (val_add, ":var_0", ":var_5"),
            (val_add, ":var_1", ":var_6"),
            (str_store_faction_name, s9, ":var_2"),
            (store_div, reg1, ":var_5", ":var_6"),
            (display_message, "@## {s9} average strength: {reg1}", 0x30FFC8),
        (try_end),
        (store_div, reg1, ":var_0", ":var_1"),
        (display_message, "@#### Overall average strength: {reg1}", 0x30FFC8),
    ], "."),

    ("calcmercs", [],
    "Spawn mercs and print strength",
    [
        (try_for_range, ":var_0", "pt_player_merc_mettenheim", "pt_player_merc_cheaters"),
            (neg|eq, ":var_0", "pt_player_merc_mettenheim_2"),
            (neg|eq, ":var_0", "pt_player_merc_red_brotherhood_2"),
            (spawn_around_party, "p_main_party", ":var_0"),
            (assign, ":var_1", reg0),
            (try_begin),
                (this_or_next|eq, ":var_0", "pt_player_merc_mettenheim"),
                (eq, ":var_0", "pt_player_merc_red_brotherhood"),
                (val_add, ":var_0", 1),
                (party_add_template, ":var_1", ":var_0"),
            (try_end),
            (call_script, "script_party_calculate_strength", ":var_1", 0),
            (str_store_party_name, s4, ":var_1"),
            (display_message, "@{s4}: strength {reg0}", 0x30FFC8),
        (try_end),
    ], "."),

    ("limits0", [],
    "Set template limits to 0",
    [
        (set_party_creation_random_limits, 0, 0),
        (display_message, "@Limits set to 0-0!", 0x30FFC8),
    ], "."),

    ("limits50", [],
    "Set template limits to 50",
    [
        (set_party_creation_random_limits, 50, 50),
        (display_message, "@Limits set to 50-50!", 0x30FFC8),
    ], "."),

    ("limits50", [],
    "Set template limits to 100",
    [
        (set_party_creation_random_limits, 100, 100),
        (display_message, "@Limits set to 100-100!", 0x30FFC8),
    ], "."),

    ("back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_hostile_party", 0,
"Choosen troop:{s4} ({reg4})",
"none", 
[
    (val_clamp, "$temp", "trp_farmer", "trp_town_walker_1"),
    (str_store_troop_name, s4, "$temp"),
    (assign, reg4, "$temp"),
],
[
    ("add1", [],
    "Increase by 1",
    [
        (val_add, "$temp", 1),
    ], "."),

    ("add1", [],
    "Increase by 10",
    [
        (val_add, "$temp", 10),
    ], "."),

    ("add1", [],
    "Increase by 100",
    [
        (val_add, "$temp", 100),
    ], "."),

    ("add1", [],
    "Decrease by 1",
    [
        (val_sub, "$temp", 1),
    ], "."),

    ("add1", [],
    "Decrease by 10",
    [
        (val_sub, "$temp", 10),
    ], "."),

    ("add1", [],
    "Decrease by 100",
    [
        (val_sub, "$temp", 100),
    ], "."),

    ("spawn", [],
    "Spawn a party with 100 troops!",
    [
        (spawn_around_party, "p_main_party", "pt_none"),
        (assign, ":var_0", reg0),
        (party_add_members, ":var_0", "$temp", 100),
        (party_set_faction, ":var_0", "fac_outlaws"),
        (party_set_name, ":var_0", "@The Hundred"),
        (display_message, "@The Hundred are upon you!", 0x30FFC8),
        (change_screen_return),
    ], "."),

    ("back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_quests35", 0,
"Select an option:",
"none", [],
[
    ("tavern_assassin", [],
    "Tavern Assassin",
    [
        (set_show_messages, 0),
        (try_for_range, ":var_0", "trp_knight_1_1", "trp_kingdom_1_pretender"),
            (call_script, "script_troop_change_relation_with_troop", "trp_player", ":var_0", -40),
            (troop_set_slot, ":var_0", slot_lord_reputation_type, 5),
        (try_end),
        (try_for_range, ":var_1", "fac_dragon_knights", "fac_noldor_castle"),
            (call_script, "script_change_player_relation_with_faction", ":var_1", -40),
        (try_end),
        (set_show_messages, 1),
        (display_message, "@You have now made enemies with all lords and all orders ... visit some taverns now ... ", 0x30FFC8),
        (change_screen_return),
    ], "."),

    ("rescue_daughter", [],
    "Rescue daughter",
    [
        (call_script, "script_end_quest", "qst_rescue_daughter"),
        (try_for_range, ":var_0", "p_village_1", "p_salt_mine"),
            (party_slot_eq, ":var_0", 40, 0),
            (party_set_slot, ":var_0", 40, "trp_knight_1_5"),
        (try_end),
        (try_for_range, ":var_1", "qst_deliver_grain", "qst_eliminate_bandits_infesting_village"),
            (quest_set_slot, ":var_1", 25, 10),
        (try_end),
        (quest_set_slot, "qst_rescue_daughter", 25, 0),
        (display_message, "@Daughter waiting to be rescued, talk to a village elder.", 0x30FFC8),
        (change_screen_return),
    ], "."),

    ("escort_peasants", [],
    "Escort peasants",
    [
        (call_script, "script_end_quest", "qst_escort_peasants"),
        (try_for_range, ":var_0", "qst_deliver_grain", "qst_eliminate_bandits_infesting_village"),
            (quest_set_slot, ":var_0", 25, 10),
        (try_end),
        (quest_set_slot, "qst_escort_peasants", 25, 0),
        (display_message, "@Peasants waiting to be escorted, talk to a village elder.", 0x30FFC8),
        (change_screen_return),
    ], "."),

    ("order_bounty", [],
    "Order bounty hunting",
    [
        (call_script, "script_end_quest", "qst_order_bounty"),
        (quest_set_slot, "qst_order_bounty", 25, 0),
        (display_message, "@Bounties await, talk to a friendly Order guard.", 0x30FFC8),
        (change_screen_return),
    ], "."),

    ("back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_economy", 0,
"Select an option:",
"none", [],
[
    ("camp_economy_listcenters", [],
    "List all centers",
    [
        (jump_to_menu, "mnu_camp_economy_view"),
    ], "."),

    ("camp_economy_listprices", [],
    "List average prices",
    [
        (jump_to_menu, "mnu_camp_economy_prices"),
    ], "."),

    ("camp_economy_centergoods", [],
    "View data on the nearest center",
    [
        (jump_to_menu, "mnu_camp_economy_center"),
    ], "."),

    ("camp_economy_market_towns", [],
    "View market towns",
    [
        (jump_to_menu, "mnu_camp_economy_markets"),
    ], "."),

    ("camp_economy_centerresetall", [],
    "Reset all prices to 1000",
    [
        (try_for_range, ":var_0", "itm_spice", "itm_baggage_train"),
            (store_sub, ":var_1", ":var_0", "itm_spice"),
            (val_add, ":var_1", 301),
            (try_for_range, ":var_2", "p_town_1", "p_salt_mine"),
                (party_set_slot, ":var_2", ":var_1", 1000),
            (try_end),
        (try_end),
        (display_message, "@Prices reset."),
    ], "."),

    ("camp_economy_cycle", [],
    "Update cycle for all trade goods prices",
    [
        (assign, ":var_0", 1000000),
        (try_for_range, ":var_1", "p_town_1", "p_salt_mine"),
            (party_get_position, pos1, ":var_1"),
            (store_distance_to_party_from_party, ":var_2", ":var_1", "p_main_party"),
            (try_begin),
                (neg|ge, ":var_2", ":var_0"),
                (assign, ":var_0", ":var_2"),
                (assign, ":var_3", ":var_1"),
            (try_end),
        (try_end),
        (store_sub, ":var_4", "itm_grain", "itm_spice"),
        (val_add, ":var_4", 301),
        (store_sub, ":var_5", "itm_bread", "itm_spice"),
        (val_add, ":var_5", 301),
        (party_get_slot, ":var_6", ":var_3", ":var_4"),
        (party_get_slot, ":var_7", ":var_3", ":var_5"),
        (call_script, "script_update_trade_good_prices"),
        (party_get_slot, ":var_8", ":var_3", ":var_4"),
        (party_get_slot, ":var_9", ":var_3", ":var_5"),
        (call_script, "script_update_trade_good_prices"),
        (party_get_slot, ":var_10", ":var_3", ":var_4"),
        (party_get_slot, ":var_11", ":var_3", ":var_5"),
        (call_script, "script_update_trade_good_prices"),
        (party_get_slot, ":var_12", ":var_3", ":var_4"),
        (party_get_slot, ":var_13", ":var_3", ":var_5"),
        (call_script, "script_average_trade_good_prices"),
        (party_get_slot, ":var_14", ":var_3", ":var_4"),
        (party_get_slot, ":var_15", ":var_3", ":var_5"),
        (call_script, "script_average_trade_good_prices"),
        (party_get_slot, ":var_16", ":var_3", ":var_4"),
        (party_get_slot, ":var_17", ":var_3", ":var_5"),
        (str_store_party_name, s4, ":var_3"),
        (assign, reg1, ":var_6"),
        (assign, reg2, ":var_8"),
        (assign, reg3, ":var_10"),
        (assign, reg4, ":var_12"),
        (assign, reg5, ":var_14"),
        (assign, reg6, ":var_16"),
        (display_message, "@Grain price in {s4}: {reg1} U {reg2} {reg3} {reg4} A {reg5} {reg6}."),
        (assign, reg1, ":var_7"),
        (assign, reg2, ":var_9"),
        (assign, reg3, ":var_11"),
        (assign, reg4, ":var_13"),
        (assign, reg5, ":var_15"),
        (assign, reg6, ":var_17"),
        (display_message, "@Bread price in {s4}: {reg1} U {reg2} {reg3} {reg4} A {reg5} {reg6}."),
    ], "."),

    ("camp_economy_back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_economy_markets", 0,
"{s2}",
"none", 
[
    (str_store_string, s2, "@Villages per town: market (bound)^"),
    (assign, ":var_0", 0),
    (assign, ":var_1", 0),
    (try_for_range, ":var_2", "p_town_1", "p_castle_1"),
        (assign, ":var_3", 0),
        (assign, ":var_4", 0),
        (try_for_range, ":var_5", "p_village_1", "p_salt_mine"),
            (party_slot_eq, ":var_5", slot_village_market_town, ":var_2"),
            (val_add, ":var_3", 1),
            (val_add, ":var_0", 1),
            (party_slot_eq, ":var_5", slot_village_bound_center, ":var_2"),
            (val_add, ":var_4", 1),
            (val_add, ":var_1", 1),
        (try_end),
        (assign, reg1, ":var_3"),
        (assign, reg2, ":var_4"),
        (str_store_party_name, s5, ":var_2"),
        (str_store_string, s2, "@{s2}^{s5}: {reg1} ({reg2})"),
    (try_end),
    (val_add, ":var_1", "p_village_1"),
    (val_sub, ":var_1", "p_castle_1"),
    (assign, reg1, ":var_0"),
    (assign, reg2, ":var_1"),
    (str_store_string, s2, "@{s2}^^Total villages: {reg1} (Bound: {reg2})"),
],
[
    ("continue", [],
    "Back to economy menu.",
    [
        (jump_to_menu, "mnu_camp_economy"),
    ], "."),

]),

("camp_economy_center", 0,
"{s2}",
"none", 
[
    (assign, ":var_0", 1000000),
    (try_for_range, ":var_1", "p_town_1", "p_salt_mine"),
        (party_get_position, pos1, ":var_1"),
        (store_distance_to_party_from_party, ":var_2", ":var_1", "p_main_party"),
        (try_begin),
            (neg|ge, ":var_2", ":var_0"),
            (assign, ":var_0", ":var_2"),
            (assign, ":var_3", ":var_1"),
        (try_end),
    (try_end),
    (str_clear, s2),
    (assign, ":var_4", 0),
    (try_for_range, ":var_5", "itm_spice", "itm_baggage_train"),
        (try_begin),
            (is_between, ":var_3", "p_village_1", "p_salt_mine"),
            (item_get_slot, ":var_6", ":var_5", slot_item_rural_demand),
        (else_try),
            (item_get_slot, ":var_6", ":var_5", slot_item_urban_demand),
        (try_end),
        (try_begin),
            (gt, ":var_6", 2),
            (store_div, ":var_7", ":var_6", 3),
        (else_try),
            (assign, ":var_7", 0),
        (try_end),
        (store_sub, ":var_8", ":var_5", "itm_spice"),
        (val_add, ":var_8", 301),
        (party_get_slot, ":var_9", ":var_3", ":var_8"),
        (store_sub, ":var_10", ":var_9", 950),
        (try_begin),
            (gt, ":var_10", 100),
            (val_div, ":var_10", 100),
            (val_min, ":var_10", ":var_7"),
        (else_try),
            (assign, ":var_10", 0),
        (try_end),
        (call_script, "script_center_get_production", ":var_3", ":var_5"),
        (assign, reg3, reg0),
        (call_script, "script_center_get_consumption", ":var_3", ":var_5"),
        (assign, reg4, reg0),
        (assign, reg5, ":var_9"),
        (str_store_item_name, s10, ":var_5"),
        (assign, reg6, ":var_10"),
        (str_store_string, s2, "@{s2}^{s10}: {reg6} (Prod:{reg3}/{reg4} Price:{reg5})"),
        (val_add, ":var_4", ":var_10"),
    (try_end),
    (str_store_string, s3, "@."),
    (try_begin),
        (is_between, ":var_3", "p_town_1", "p_castle_1"),
        (try_for_range, ":var_11", "p_village_1", "p_salt_mine"),
            (party_slot_eq, ":var_11", slot_village_market_town, ":var_3"),
            (str_store_party_name, s5, ":var_11"),
            (str_store_string, s3, "@{s5} {s3}"),
        (try_end),
    (try_end),
    (call_script, "script_center_get_goods_availability", ":var_3"),
    (assign, reg3, reg0),
    (call_script, "script_get_center_ideal_prosperity", ":var_3"),
    (assign, reg4, reg0),
    (party_get_slot, reg1, ":var_3", 290),
    (party_get_slot, reg2, ":var_3", slot_town_prosperity),
    (call_script, "script_get_prosperity_text_to_s50", ":var_3"),
    (str_store_party_name, s4, ":var_3"),
    (str_store_string, s2, "@Report for {s4}:^Economy: {reg1}^Prosperity: {reg2}[{reg4}] {s50}^Hardship: {reg3}^Market villages: {s3}^{s2}"),
],
[
    ("continue", [],
    "Back to economy menu.",
    [
        (jump_to_menu, "mnu_camp_economy"),
    ], "."),

]),

("camp_economy_view", 0,
"{s2}",
"none", 
[
    (str_clear, s2),
    (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
        (try_begin),
            (this_or_next|eq, ":var_0", "p_castle_1"),
            (eq, ":var_0", "p_village_1"),
            (str_store_string, s2, "@{s2}^"),
        (try_end),
        (call_script, "script_center_get_goods_availability", ":var_0"),
        (assign, reg3, reg0),
        (call_script, "script_get_center_ideal_prosperity", ":var_0"),
        (assign, reg4, reg0),
        (party_get_slot, reg1, ":var_0", 290),
        (party_get_slot, reg2, ":var_0", slot_town_prosperity),
        (str_store_party_name, s4, ":var_0"),
        (str_store_string, s2, "@{s2}^{s4}: E: {reg1} P: {reg2}[{reg4}] H: {reg3}"),
    (try_end),
    (str_store_string, s2, "@The current fief income is: ^{s2}"),
],
[
    ("continue", [],
    "Back to economy menu.",
    [
        (jump_to_menu, "mnu_camp_economy"),
    ], "."),

]),

("camp_economy_prices", 0,
"{s2}",
"none", 
[
    (str_store_string, s2, "@Average prices in Pendor [Prod/Cons]^"),
    (try_for_range, ":var_0", "itm_spice", "itm_baggage_train"),
        (store_sub, ":var_1", ":var_0", "itm_spice"),
        (val_add, ":var_1", 301),
        (assign, ":var_2", 0),
        (assign, ":var_3", 0),
        (assign, ":var_4", 0),
        (assign, ":var_5", 0),
        (try_for_range, ":var_6", "p_town_1", "p_salt_mine"),
            (neg|is_between, ":var_6", "p_castle_1", "p_village_1"),
            (val_add, ":var_2", 1),
            (call_script, "script_center_get_production", ":var_6", ":var_0"),
            (assign, ":var_7", reg2),
            (call_script, "script_center_get_consumption", ":var_6", ":var_0"),
            (store_add, ":var_8", reg1, reg2),
            (party_get_slot, ":var_9", ":var_6", ":var_1"),
            (val_add, ":var_3", ":var_9"),
            (val_add, ":var_4", ":var_7"),
            (val_add, ":var_5", ":var_8"),
        (try_end),
        (assign, ":var_10", ":var_4"),
        (assign, ":var_11", ":var_5"),
        (val_div, ":var_3", ":var_2"),
        (assign, reg6, ":var_3"),
        (assign, reg12, ":var_10"),
        (assign, reg13, ":var_11"),
        (str_store_item_name, s10, ":var_0"),
        (str_store_string, s2, "@{s2}^{s10}: {reg6} [{reg12}/{reg13}]"),
    (try_end),
],
[
    ("continue", [],
    "Back to economy menu.",
    [
        (jump_to_menu, "mnu_camp_economy"),
    ], "."),

]),

("camp_noldor", 0,
"Select an option:",
"none", [],
[
    ("test_noldor_friend", [],
    "Make me a Noldor friend (30)",
    [
        (call_script, "script_set_player_relation_with_faction", "fac_noldor_elves", 30),
        (display_message, "@Noldor relations set to 30", 0x30FFC8),
    ], "."),

    ("test_noldor_friend2", [],
    "Make me a Noldor supporter (15) - enables the quest",
    [
        (call_script, "script_set_player_relation_with_faction", "fac_noldor_elves", 15),
        (display_message, "@Noldor relations set to 15", 0x30FFC8),
    ], "."),

    ("test_noldor_enemy", [],
    "Make me a Noldor enemy (-10)",
    [
        (call_script, "script_set_player_relation_with_faction", "fac_noldor_elves", -10),
        (display_message, "@Noldor relations set to -10", 0x30FFC8),
    ], "."),

    ("test_noldor_quest", [],
    "Complete the Noldor quest (access the castle)",
    [
        (quest_set_slot, "qst_marauding_jatu", 11, 3),
        (call_script, "script_set_player_relation_with_faction", "fac_noldor_elves", 30),
        (display_message, "@Noldor castle accessible", 0x30FFC8),
    ], "."),

    ("test_noldor_quest", [],
    "Reset the Noldor quest",
    [
        (quest_set_slot, "qst_marauding_jatu", 11, 0),
        (display_message, "@Noldor quest reset", 0x30FFC8),
    ], "."),

    ("test_noldor_tournament", [],
    "Start a Noldor tournament",
    [
        (party_set_slot, "p_castle_noldor", slot_town_has_tournament, 1),
        (display_message, "@Noldor tournament started", 0x30FFC8),
    ], "."),

    ("test_noldor_trader", [],
    "Regenerate merchant inventory",
    [
        (try_for_range, ":var_0", 0, 7),
            (reset_item_probabilities, 100),
            (set_merchandise_modifier_quality, 150),
            (troop_loot_troop, "trp_noldor_merchant", "trp_noldor_warrior", 300),
            (troop_loot_troop, "trp_noldor_merchant", "trp_noldor_warrior", 300),
            (troop_loot_troop, "trp_noldor_merchant", "trp_noldor_ranger", 300),
            (troop_loot_troop, "trp_noldor_merchant", "trp_noldor_ranger", 300),
            (troop_loot_troop, "trp_noldor_merchant", "trp_noldor_noble", 300),
            (troop_loot_troop, "trp_noldor_merchant", "trp_noldor_maiden", 300),
            (troop_loot_troop, "trp_noldor_merchant", "trp_noldor_knight", 300),
            (troop_get_inventory_capacity, ":var_1", "trp_noldor_merchant"),
            (try_for_range, ":var_2", 0, ":var_1"),
                (troop_get_inventory_slot, ":var_3", "trp_noldor_merchant", ":var_2"),
                (ge, ":var_3", 0),
                (try_begin),
                    (this_or_next|eq, ":var_3", "itm_pop_loot"),
                    (eq, ":var_3", "itm_pop_noldor_goods"),
                    (troop_set_inventory_slot, "trp_noldor_merchant", ":var_2", -1),
                (try_end),
            (try_end),
            (troop_ensure_inventory_space, "trp_noldor_merchant", 30),
            (troop_sort_inventory, "trp_noldor_merchant"),
            (store_troop_gold, reg6, "trp_noldor_merchant"),
            (neg|ge, reg6, 900),
            (store_random_in_range, ":var_4", 2800, 5000),
            (call_script, "script_troop_add_gold", "trp_noldor_merchant", ":var_4"),
        (try_end),
        (display_message, "@One week's worth of new inventory added", 0x30FFC8),
    ], "."),

    ("test_noldor_prize", [],
    "Give me a Noldor prize!",
    [
        (str_clear, s8),
        (store_random_in_range, ":var_0", 0, 100),
        (store_random_in_range, ":var_1", 0, 100),
        (store_random_in_range, ":var_2", 0, 100),
        (assign, ":var_3", 0),
        (try_begin),
            (neg|ge, ":var_0", 20),
            (assign, ":var_4", "itm_pop_qualis"),
        (else_try),
            (neg|ge, ":var_0", 40),
            (try_begin),
                (neg|ge, ":var_1", 50),
                (assign, ":var_4", "itm_pop_noldor_longsword"),
            (else_try),
                (neg|ge, ":var_1", 80),
                (assign, ":var_4", "itm_pop_noldor_runesword"),
            (else_try),
                (assign, ":var_4", "itm_pop_noldor_bastard"),
            (try_end),
            (try_begin),
                (neg|ge, ":var_2", 50),
                (assign, ":var_3", 10),
            (else_try),
                (neg|ge, ":var_2", 80),
                (assign, ":var_3", 13),
            (else_try),
                (neg|ge, ":var_2", 80),
                (assign, ":var_3", 14),
            (else_try),
                (assign, ":var_3", 17),
            (try_end),
        (else_try),
            (neg|ge, ":var_0", 50),
            (assign, ":var_4", "itm_pop_noldor_bow"),
            (try_begin),
                (neg|ge, ":var_2", 10),
                (assign, ":var_3", 17),
            (try_end),
        (else_try),
            (neg|ge, ":var_0", 80),
            (try_begin),
                (neg|ge, ":var_1", 10),
                (assign, ":var_4", "itm_pop_noldor_inf_helm"),
            (else_try),
                (neg|ge, ":var_1", 20),
                (assign, ":var_4", "itm_pop_noldor_capt_helm"),
            (else_try),
                (neg|ge, ":var_1", 25),
                (assign, ":var_4", "itm_pop_noldor_knight_helm"),
            (else_try),
                (neg|ge, ":var_1", 30),
                (assign, ":var_4", "itm_pop_noldor_noble_armor"),
            (else_try),
                (neg|ge, ":var_1", 35),
                (assign, ":var_4", "itm_pop_noldor_ranger_garb"),
            (else_try),
                (neg|ge, ":var_1", 50),
                (assign, ":var_4", "itm_pop_noldor_archer_garb"),
            (else_try),
                (neg|ge, ":var_1", 65),
                (assign, ":var_4", "itm_pop_noldor_female_armor"),
            (else_try),
                (neg|ge, ":var_1", 75),
                (assign, ":var_4", "itm_pop_noldor_rune_armor"),
            (else_try),
                (neg|ge, ":var_1", 80),
                (assign, ":var_4", "itm_pop_noldor_ancient_plate"),
            (else_try),
                (assign, ":var_4", "itm_pop_noldor_boots"),
            (try_end),
            (try_begin),
                (neg|ge, ":var_2", 60),
                (assign, ":var_3", 25),
            (else_try),
                (neg|ge, ":var_2", 90),
                (assign, ":var_3", 27),
            (else_try),
                (assign, ":var_3", 29),
            (try_end),
            (try_begin),
                (eq, ":var_4", "itm_pop_noldor_boots"),
                (try_begin),
                    (eq, ":var_3", 27),
                    (assign, ":var_3", 24),
                (else_try),
                    (eq, ":var_3", 29),
                    (assign, ":var_3", 26),
                (try_end),
            (try_end),
        (else_try),
            (try_begin),
                (neg|ge, ":var_1", 20),
                (assign, ":var_4", "itm_pop_noldor_grey_horse"),
            (else_try),
                (neg|ge, ":var_1", 40),
                (assign, ":var_4", "itm_pop_noldor_dark_horse"),
            (else_try),
                (neg|ge, ":var_1", 60),
                (assign, ":var_4", "itm_pop_noldor_gold_horse"),
            (else_try),
                (neg|ge, ":var_1", 90),
                (assign, ":var_4", "itm_pop_noldor_pony_horse"),
            (else_try),
                (assign, ":var_4", "itm_pop_noldor_spirit_horse"),
            (try_end),
            (try_begin),
                (neg|ge, ":var_2", 30),
                (assign, ":var_3", 35),
            (else_try),
                (neg|ge, ":var_2", 60),
                (assign, ":var_3", 18),
            (else_try),
                (neg|ge, ":var_2", 90),
                (assign, ":var_3", 32),
            (else_try),
                (assign, ":var_3", 36),
            (try_end),
        (try_end),
        (troop_add_item, "trp_player", ":var_4", ":var_3"),
        (str_store_item_name, s21, ":var_4"),
        (str_store_string, s8, "@You have been presented with an exquisite {s21} from the Noldor Council."),
        (display_message, "@{s8}", 0x30FFC8),
    ], "."),

    ("camp_noldor_back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("test_heartbeat", 0,
"Select an option:",
"none", [],
[
    ("test_heartbeat_generate", [],
    "Generate heartbeat quest",
    [
        (call_script, "script_get_number_of_hero_centers", "trp_player"),
        (assign, ":var_0", reg0),
        (try_begin),
            (gt, ":var_0", 0),
            (store_random_in_range, ":var_1", 0, ":var_0"),
            (call_script, "script_troop_get_leaded_center_with_index", "trp_player", ":var_1"),
            (assign, ":var_2", reg0),
            (store_random_in_range, ":var_3", 1, 14),
            (party_set_slot, ":var_2", 296, ":var_3"),
            (call_script, "script_add_notification_menu", "mnu_heartbeat_quest", ":var_2", 0),
            (assign, reg0, ":var_3"),
            (str_store_party_name, s4, ":var_2"),
            (display_message, "@Generated quest #{reg0} in {s4} - notification pending"),
        (try_end),
    ], "."),

    ("camp_heartbeat_back", [],
    "Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("camp_achieve", 0,
"Select an option:",
"none", [],
[
    ("camp_achieve_all", [],
    "Give me all achievements",
    [
        (assign, "$g_achieve_bitfield", 268435455),
        (display_message, "@All achievements given. Check report."),
    ], "."),

    ("camp_achieve_none", [],
    "Clear all achievements",
    [
        (assign, "$g_achieve_bitfield", 0),
        (assign, "$g_achieve_bits_delay_popup", 0),
        (display_message, "@All achievements cleared."),
    ], "."),

    ("camp_achieve_notify", [],
    "Review all notifications",
    [
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_kill_battle", 0),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_kills_1", 1),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_kills_2", 2),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_vic_1", 3),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_vic_2", 4),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_heroes_1", 5),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_heroes_2", 6),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_mysts", 7),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_snakes", 8),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_jatu", 9),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_heretics", 10),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_tour_1", 11),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_tour_2", 12),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_rnwn_1", 13),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_rnwn_2", 14),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_honor", 15),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_king", 16),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_persuader", 17),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_builder", 18),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_quests", 19),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_fquests", 20),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_captured", 21),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_caravan", 22),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_village", 23),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_cheater", 24),
        (call_script, "script_add_notification_menu", "mnu_achievement_notify", "str_achieve_gm", 25),
        (display_message, "@Notifications queued. Should trigger anytime now."),
        (change_screen_map),
    ], "."),

    ("camp_achieve_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_honor", 0,
"Select an option:",
"none", [],
[
    ("camp_honor_kotd", [],
    "Give me 10 Dragon troops",
    [
        (party_add_members, "p_main_party", "trp_dragon_drake", 5),
        (party_add_members, "p_main_party", "trp_dragon_knight", 5),
        (display_message, "@10 Dragon troops joined the party"),
    ], "."),

    ("camp_honor_kors", [],
    "Give me 10 Lion troops",
    [
        (party_add_members, "p_main_party", "trp_lion_squire", 5),
        (party_add_members, "p_main_party", "trp_lion_knight", 5),
        (display_message, "@10 Squires of the Lion joined the party"),
    ], "."),

    ("camp_honor_ei", [],
    "Give me 10 Empire Mortals",
    [
        (party_add_members, "p_main_party", "trp_empire_mortal", 5),
        (party_add_members, "p_main_party", "trp_empire_immortal", 5),
        (display_message, "@10 Empire Mortals joined the party"),
    ], "."),

    ("camp_honor_dsw", [],
    "Give me 10 D'Shar Dustriders",
    [
        (party_add_members, "p_main_party", "trp_dshar_dustrider", 10),
        (display_message, "@10 D'Shar Dustriders joined the party"),
    ], "."),

    ("camp_honor_lv", [],
    "Give me 10 Lady Einherjar",
    [
        (party_add_members, "p_main_party", "trp_lady_einherjar", 10),
        (display_message, "@10 Lady Einherjar joined the party"),
    ], "."),

    ("camp_honor_kotg", [],
    "Give me 10 Knights of the Griffon",
    [
        (party_add_members, "p_main_party", "trp_griffon_knight", 10),
        (display_message, "@10 Knights of the Griffon joined the party"),
    ], "."),

    ("camp_honor_kotf", [],
    "Give me 10 Knights and Talons of the Falcon",
    [
        (party_add_members, "p_main_party", "trp_falcon_talon", 10),
        (party_add_members, "p_main_party", "trp_falcon_knight", 10),
        (display_message, "@10 Knights and Talons of the Falcon joined the party"),
    ], "."),

    ("camp_honor_kors", [],
    "Give me 10 Ravenspear Knights",
    [
        (party_add_members, "p_main_party", "trp_raven_spear_knight", 10),
        (display_message, "@10 Ravenspear knights joined the party"),
    ], "."),

    ("camp_honor_korc", [],
    "Give me 10 Radiant Cross Knights",
    [
        (party_add_members, "p_main_party", "trp_radiant_cross_knight", 10),
        (display_message, "@10 Radiant Cross Knights joined the party"),
    ], "."),

    ("camp_honor_rocc", [],
    "Give me 10 Rangers of the Clarion Call",
    [
        (party_add_members, "p_main_party", "trp_clarion_ranger", 10),
        (display_message, "@10 Rangers of the Clarion Call joined the party"),
    ], "."),

    ("camp_honor_kotdw", [],
    "Give me 10 Knight of the Dawn",
    [
        (party_add_members, "p_main_party", "trp_dawn_knight", 10),
        (display_message, "@10 Knights of the Dawn joined the party"),
    ], "."),

    ("camp_honor_koteg", [],
    "Give me 10 Knights of the Ebony Gauntlet",
    [
        (party_add_members, "p_main_party", "trp_ebony_gauntlet", 10),
        (display_message, "@10 Knights of the Ebony Gauntlet joined the party"),
    ], "."),

    ("camp_honor_slc", [],
    "Give me 10 Shadow Legion Marinae",
    [
        (party_add_members, "p_main_party", "trp_shadow_marinus", 10),
        (display_message, "@10 Shadow Legion Marinae joined the party"),
    ], "."),

    ("camp_honor_sr", [],
    "Give me 10 Silvermist Rangers",
    [
        (party_add_members, "p_main_party", "trp_silvermist_ranger", 10),
        (display_message, "@10 Silvermist Rangers joined the party"),
    ], "."),

    ("camp_honor_koe", [],
    "Give me 10 Knights of Eventide",
    [
        (party_add_members, "p_main_party", "trp_eventide_knight", 10),
        (display_message, "@10 Knights of Eventide joined the party"),
    ], "."),

    ("camp_honor_back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_cool", 0,
"Select an option:",
"none", [],
[
    ("camp_cool_ha", [],
    "Give me 100 Heroine Adventurers",
    [
        (party_add_members, "p_main_party", "trp_heroine_adventurer", 100),
        (display_message, "@100 Heroine Adventurers joined the party"),
    ], "."),

    ("camp_cool_ham", [],
    "Give me 100 Hero Adventurers",
    [
        (party_add_members, "p_main_party", "trp_hero_adventurer", 100),
        (display_message, "@100 Hero Adventurers joined the party"),
    ], "."),

    ("camp_cool_jmr", [],
    "Give me 100 Jatu Mercenary Riders",
    [
        (party_add_members, "p_main_party", "trp_jatu_merc", 100),
        (display_message, "@100 Jatu Mercenary Riders joined the party"),
    ], "."),

    ("camp_cool_mhc", [],
    "Give me 100 Marleons Heavy Cavalry",
    [
        (party_add_members, "p_main_party", "trp_marleons_cavalry", 100),
        (display_message, "@100 Marleons Heavy Cavalry joined the party"),
    ], "."),

    ("camp_cool_rkk", [],
    "Give me 100 Ravenstern Highlanders",
    [
        (party_add_members, "p_main_party", "trp_rav_kierguard_knight", 100),
        (display_message, "@100 Ravenstern Highlanders joined the party"),
    ], "."),

    ("camp_cool_dda", [],
    "Give me 100 D'Shar Djaha Archers",
    [
        (party_add_members, "p_main_party", "trp_dshar_djaha", 100),
        (display_message, "@100 D'Shar Djaha Archers joined the party"),
    ], "."),

    ("camp_cool_dda", [],
    "Give me 100 Valdis Huscarls",
    [
        (party_add_members, "p_main_party", "trp_valdis_huscarl", 100),
        (display_message, "@100 Valdis Huscarls joined the party"),
    ], "."),

    ("camp_cool_ntk", [],
    "Give me 100 Noldor Twilight Knights",
    [
        (party_add_members, "p_main_party", "trp_noldor_knight", 100),
        (display_message, "@100 Noldor Twilight Knights joined the party"),
    ], "."),

    ("camp_cool_nmr", [],
    "Give me 100 Noldor Maiden Rangers",
    [
        (party_add_members, "p_main_party", "trp_noldor_maiden", 100),
        (display_message, "@100 Noldor Maiden Rangers joined the party"),
    ], "."),

    ("camp_cool_nr", [],
    "Give me 100 Noldor Rangers",
    [
        (party_add_members, "p_main_party", "trp_noldor_ranger", 100),
        (display_message, "@100 Noldor Rangers joined the party"),
    ], "."),

    ("camp_cool_kjk", [],
    "Give me 100 K'Juda's Kajahars",
    [
        (party_add_members, "p_main_party", "trp_kjuda_kajahar", 100),
        (display_message, "@100 K'Juda's Kajahars joined the party"),
    ], "."),

    ("camp_cool_dg", [],
    "Give me 100 Doomguides",
    [
        (party_add_members, "p_main_party", "trp_doomguide", 100),
        (display_message, "@100 Doomguides joined the party"),
    ], "."),

    ("camp_cool_os", [],
    "Give me 100 Omen Seekers",
    [
        (party_add_members, "p_main_party", "trp_omen_seeker", 100),
        (display_message, "@100 Omen Seekers joined the party"),
    ], "."),

    ("camp_cool_more", [],
    "More cool troops...",
    [
        (jump_to_menu, "mnu_camp_cool2"),
    ], "."),

    ("camp_cool_back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_cool2", 0,
"Select an option:",
"none", [],
[
    ("camp_cool_05", [],
    "Give me a Specialty Troop",
    [
        (party_add_members, "p_main_party", "trp_dshar_djaha", 1),
        (party_add_members, "p_main_party", "trp_valdis_huscarl", 1),
        (party_add_members, "p_main_party", "trp_empire_knight", 1),
        (party_add_members, "p_main_party", "trp_marleons_cavalry", 1),
        (party_add_members, "p_main_party", "trp_empire_guardian_knight", 1),
        (display_message, "@A specialty troop has joined the party"),
    ], "."),

    ("camp_cool2_dli", [],
    "Give me 100 Dread Legion Infantry",
    [
        (party_add_members, "p_main_party", "trp_dread_infantry", 100),
        (display_message, "@100 Dread Legion Infantry joined the party"),
    ], "."),

    ("camp_cool2_ak", [],
    "Give me 100 Anaconda Knights",
    [
        (party_add_members, "p_main_party", "trp_anaconda_knight", 100),
        (display_message, "@100 Anaconda Knights joined the party"),
    ], "."),

    ("camp_cool2_fr", [],
    "Give me 100 Fallen Revenants",
    [
        (party_add_members, "p_main_party", "trp_fallen_revenant", 100),
        (display_message, "@100 Fallen Revenants joined the party"),
    ], "."),

    ("camp_cool2_dm", [],
    "Give me 100 Demonic Magni",
    [
        (party_add_members, "p_main_party", "trp_demonic_magnus", 100),
        (display_message, "@100 Demonic Magni joined the party"),
    ], "."),

    ("camp_cool2_hm", [],
    "Give me 100 Heretic Invokers",
    [
        (party_add_members, "p_main_party", "trp_heretic_invoker", 100),
        (display_message, "@100 Heretic Invokers joined the party"),
    ], "."),

    ("camp_cool2_back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_regular", 0,
"Select an option:",
"none", [],
[
    ("camp_regular_Mettenheim", [],
    "Give me a Mettenheim troops",
    [
        (party_add_members, "p_main_party", "trp_mett_infantry", 4),
        (party_add_members, "p_main_party", "trp_mett_crossbow", 5),
        (party_add_members, "p_main_party", "trp_mett_greatsword", 3),
        (party_add_members, "p_main_party", "trp_mett_hauptmann", 3),
        (party_add_members, "p_main_party", "trp_mett_forlorn", 3),
        (display_message, "@A Mettenheim company has joined your party"),
    ], "."),

    ("camp_regular_Veccavian", [],
    "Give me a Veccavian company",
    [
        (party_add_members, "p_main_party", "trp_veccavi_kral", 4),
        (party_add_members, "p_main_party", "trp_veccavi_krom", 5),
        (party_add_members, "p_main_party", "trp_veccavi_archer", 3),
        (party_add_members, "p_main_party", "trp_veccavi_horse", 3),
        (party_add_members, "p_main_party", "trp_veccavi_knight", 3),
        (party_add_members, "p_main_party", "trp_veccavi_queen_guard", 3),
        (display_message, "@A Veccavian company has joined your party"),
    ], "."),

    ("camp_regular_Veccavian", [],
    "Give me a Melitine company",
    [
        (party_add_members, "p_main_party", "trp_melitine_archer", 6),
        (party_add_members, "p_main_party", "trp_melitine_infantry", 4),
        (party_add_members, "p_main_party", "trp_melitine_shock_infantry", 3),
        (party_add_members, "p_main_party", "trp_melitine_lancer", 3),
        (party_add_members, "p_main_party", "trp_melitine_horse_archer", 3),
        (party_add_members, "p_main_party", "trp_melitine_cataphract", 2),
        (display_message, "@A Melitine company has joined your party"),
    ], "."),

    ("camp_regular_Sarleon", [],
    "Give me a Sarleon company",
    [
        (party_add_members, "p_main_party", "trp_sarleon_recruit", 1),
        (party_add_members, "p_main_party", "trp_sarleon_militia", 1),
        (party_add_members, "p_main_party", "trp_sarleon_trained_militia", 1),
        (party_add_members, "p_main_party", "trp_sarleon_footman", 1),
        (party_add_members, "p_main_party", "trp_sarleon_arm_footman", 1),
        (party_add_members, "p_main_party", "trp_sarleon_halberdier", 1),
        (party_add_members, "p_main_party", "trp_sarleon_skirmisher", 1),
        (party_add_members, "p_main_party", "trp_sarleon_longbowman", 1),
        (party_add_members, "p_main_party", "trp_sarleon_arm_longbowman", 1),
        (party_add_members, "p_main_party", "trp_sarleon_manatarms", 1),
        (party_add_members, "p_main_party", "trp_sarleon_knight", 1),
        (party_add_members, "p_main_party", "trp_sarleon_nobleman", 1),
        (party_add_members, "p_main_party", "trp_sarleon_squire", 1),
        (party_add_members, "p_main_party", "trp_marleons_cavalry", 1),
        (display_message, "@A Sarleon Company has joined the party"),
    ], "."),

    ("camp_regular_Ravenstern", [],
    "Give me a Ravenstern company",
    [
        (party_add_members, "p_main_party", "trp_rav_recruit", 1),
        (party_add_members, "p_main_party", "trp_rav_militia", 1),
        (party_add_members, "p_main_party", "trp_rav_skirmisher", 1),
        (party_add_members, "p_main_party", "trp_rav_archer", 1),
        (party_add_members, "p_main_party", "trp_rav_warden", 1),
        (party_add_members, "p_main_party", "trp_rav_manatarms", 1),
        (party_add_members, "p_main_party", "trp_rav_footman", 1),
        (party_add_members, "p_main_party", "trp_rav_kierguard", 1),
        (party_add_members, "p_main_party", "trp_rav_squire", 1),
        (party_add_members, "p_main_party", "trp_rav_horseman", 1),
        (party_add_members, "p_main_party", "trp_rav_knight", 1),
        (party_add_members, "p_main_party", "trp_rav_trained_militia", 1),
        (party_add_members, "p_main_party", "trp_rav_nobleman", 1),
        (party_add_members, "p_main_party", "trp_rav_ranger", 1),
        (party_add_members, "p_main_party", "trp_rav_mounted_ranger", 1),
        (display_message, "@A Ravenstern Company joined the party"),
    ], "."),

    ("camp_regular_DShar", [],
    "Give me a D'Shar company",
    [
        (party_add_members, "p_main_party", "trp_dshar_tribesman", 1),
        (party_add_members, "p_main_party", "trp_dshar_hunter", 1),
        (party_add_members, "p_main_party", "trp_dshar_nobleman", 1),
        (party_add_members, "p_main_party", "trp_dshar_noble_raider", 1),
        (party_add_members, "p_main_party", "trp_dshar_noble_cavalry", 1),
        (party_add_members, "p_main_party", "trp_dshar_warrior", 1),
        (party_add_members, "p_main_party", "trp_dshar_spearman", 1),
        (party_add_members, "p_main_party", "trp_dshar_veteran_spearman", 1),
        (party_add_members, "p_main_party", "trp_dshar_bladesman", 1),
        (party_add_members, "p_main_party", "trp_dshar_assassin", 1),
        (party_add_members, "p_main_party", "trp_dshar_bowman", 1),
        (party_add_members, "p_main_party", "trp_dshar_dervish", 1),
        (party_add_members, "p_main_party", "trp_dshar_dervish_raider", 1),
        (party_add_members, "p_main_party", "trp_dshar_blademaster", 1),
        (party_add_members, "p_main_party", "trp_dshar_djaha", 1),
        (display_message, "@A D'Shar Company joined the party"),
    ], "."),

    ("camp_regular_Fierdsvain", [],
    "Give me a Fierdsvain company",
    [
        (party_add_members, "p_main_party", "trp_fierd_recruit", 1),
        (party_add_members, "p_main_party", "trp_fierd_militia", 1),
        (party_add_members, "p_main_party", "trp_fierd_tr_militia", 1),
        (party_add_members, "p_main_party", "trp_fierd_axeman", 1),
        (party_add_members, "p_main_party", "trp_fierd_warrior", 1),
        (party_add_members, "p_main_party", "trp_fierd_huscarl", 1),
        (party_add_members, "p_main_party", "trp_fierd_hunter", 1),
        (party_add_members, "p_main_party", "trp_fierd_bowman", 1),
        (party_add_members, "p_main_party", "trp_fierd_archer", 1),
        (party_add_members, "p_main_party", "trp_fierd_light_infantry", 1),
        (party_add_members, "p_main_party", "trp_fierd_berserker", 1),
        (party_add_members, "p_main_party", "trp_fierd_armored_axeman", 1),
        (party_add_members, "p_main_party", "trp_fierd_heavy_archer", 1),
        (party_add_members, "p_main_party", "trp_fierd_noblewoman", 1),
        (party_add_members, "p_main_party", "trp_fierd_sword_maiden", 1),
        (party_add_members, "p_main_party", "trp_valkyrie", 1),
        (party_add_members, "p_main_party", "trp_valdis_huscarl", 1),
        (display_message, "@A Fierdsvain Company joined the party"),
    ], "."),

    ("camp_regular_Empire", [],
    "Give me an Empire company",
    [
        (party_add_members, "p_main_party", "trp_empire_citizen", 1),
        (party_add_members, "p_main_party", "trp_empire_recruit", 1),
        (party_add_members, "p_main_party", "trp_empire_militia", 1),
        (party_add_members, "p_main_party", "trp_empire_infantry", 1),
        (party_add_members, "p_main_party", "trp_empire_knight", 1),
        (party_add_members, "p_main_party", "trp_empire_legionnaire", 1),
        (party_add_members, "p_main_party", "trp_empire_noble_foot", 1),
        (party_add_members, "p_main_party", "trp_empire_hunter", 1),
        (party_add_members, "p_main_party", "trp_empire_skirmisher", 1),
        (party_add_members, "p_main_party", "trp_empire_crossbowman", 1),
        (party_add_members, "p_main_party", "trp_empire_arm_crossbowman", 1),
        (party_add_members, "p_main_party", "trp_empire_light_infantry", 1),
        (party_add_members, "p_main_party", "trp_empire_pikeman", 1),
        (party_add_members, "p_main_party", "trp_empire_armored_pikeman", 1),
        (party_add_members, "p_main_party", "trp_empire_gladiator", 1),
        (party_add_members, "p_main_party", "trp_empire_nobleman", 1),
        (party_add_members, "p_main_party", "trp_empire_light_cavalry", 1),
        (party_add_members, "p_main_party", "trp_empire_horseman", 1),
        (party_add_members, "p_main_party", "trp_empire_immortal", 1),
        (display_message, "@An Empire Company joined the party"),
    ], "."),

    ("camp_regular_pendor", [],
    "Give me a Pendor company",
    [
        (party_add_members, "p_main_party", "trp_pendor_foot_knight", 1),
        (party_add_members, "p_main_party", "trp_pendor_recruit", 1),
        (party_add_members, "p_main_party", "trp_pendor_militia", 1),
        (party_add_members, "p_main_party", "trp_pendor_footman", 1),
        (party_add_members, "p_main_party", "trp_pendor_swordsman", 1),
        (party_add_members, "p_main_party", "trp_pendor_manatarms", 1),
        (party_add_members, "p_main_party", "trp_pendor_cavalry", 1),
        (party_add_members, "p_main_party", "trp_pendor_mtdmanatarms", 1),
        (party_add_members, "p_main_party", "trp_pendor_nobleman", 1),
        (party_add_members, "p_main_party", "trp_pendor_squire", 1),
        (party_add_members, "p_main_party", "trp_pendor_knight", 1),
        (party_add_members, "p_main_party", "trp_pendor_light_bowman", 1),
        (party_add_members, "p_main_party", "trp_pendor_heavy_bowman", 1),
        (party_add_members, "p_main_party", "trp_pendor_armored_bowman", 1),
        (party_add_members, "p_main_party", "trp_pendor_gray_archer", 1),
        (party_add_members, "p_main_party", "trp_pendor_noble_bowman", 1),
        (display_message, "@A Pendor Company has joined the party"),
    ], "."),

    ("camp_regular_back", [],
    "Back to test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_minor", 0,
"Select an option:",
"none", 
[
    (set_spawn_radius, 3),
],
[
    ("camp_minor_eventide", [],
    "Spawn Eventide Knight Patrol",
    [
        (spawn_around_party, "p_main_party", "pt_errant_knights"),
        (assign, ":var_0", reg0),
        (party_set_faction, ":var_0", "fac_eventide_knights"),
        (party_set_name, ":var_0", "@Patrolling Kick-Ass Knights"),
        (party_add_members, ":var_0", "trp_eventide_knight", 10),
        (display_message, "@Eventide Knight Patrol spawned"),
    ], "."),

    ("camp_minor_dawn", [],
    "Spawn Dawn Knight Patrol",
    [
        (spawn_around_party, "p_main_party", "pt_errant_knights"),
        (assign, ":var_0", reg0),
        (party_set_faction, ":var_0", "fac_dawn_knights"),
        (party_set_name, ":var_0", "@Patrolling Kick-Ass Knights"),
        (party_add_members, ":var_0", "trp_dawn_knight", 10),
        (display_message, "@Dawn Knight Patrol spawned"),
    ], "."),

    ("camp_minor_ebony", [],
    "Spawn Ebony Knight Patrol",
    [
        (spawn_around_party, "p_main_party", "pt_errant_knights"),
        (assign, ":var_0", reg0),
        (party_set_faction, ":var_0", "fac_ebony_knights"),
        (party_set_name, ":var_0", "@Patrolling Kick-Ass Knights"),
        (party_add_members, ":var_0", "trp_ebony_gauntlet", 10),
        (display_message, "@Ebony Knight Patrol spawned"),
    ], "."),

    ("camp_minor_1", [],
    "Spawn Vanskerry Army",
    [
        (spawn_around_party, "p_main_party", "pt_sea_raider_army"),
        (display_message, "@Vanskerries spawned"),
    ], "."),

    ("camp_minor_2", [],
    "Spawn Heretic Army",
    [
        (spawn_around_party, "p_main_party", "pt_heretics_army"),
        (display_message, "@Heretics spawned"),
    ], "."),

    ("camp_minor_3", [],
    "Spawn Snake Cult Army",
    [
        (spawn_around_party, "p_main_party", "pt_snake_cult_army"),
        (display_message, "@Snake Cult spawned"),
    ], "."),

    ("camp_minor_4", [],
    "Spawn Mystmountain Army",
    [
        (spawn_around_party, "p_main_party", "pt_mystmountain_army"),
        (display_message, "@Mystmountains spawned"),
    ], "."),

    ("camp_minor_5", [],
    "Spawn Jatu Army",
    [
        (spawn_around_party, "p_main_party", "pt_jatu_army"),
        (display_message, "@Jatu spawned"),
    ], "."),

    ("camp_minor_6", [],
    "Spawn Noldor Patrol",
    [
        (spawn_around_party, "p_main_party", "pt_noldor_elves"),
        (display_message, "@Noldor Patrol spawned"),
    ], "."),

    ("camp_minor_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_hero", 0,
"Select an option:",
"none", 
[
    (set_spawn_radius, 2),
],
[
    ("camp_hero_1", [],
    "Spawn Three Seers",
    [
        (spawn_around_party, "p_main_party", "pt_three_seers"),
        (display_message, "@Three Seers spawned"),
    ], "."),

    ("camp_hero_2", [],
    "Spawn Alaric Von Brouhaha",
    [
        (spawn_around_party, "p_main_party", "pt_brouhaha"),
        (display_message, "@Alaric Von Brouhaha spawned"),
    ], "."),

    ("camp_hero_3", [],
    "Spawn Boris the Raven",
    [
        (spawn_around_party, "p_main_party", "pt_boristheraven"),
        (display_message, "@Boris the Raven spawned"),
    ], "."),

    ("camp_hero_4", [],
    "Spawn Burilgi the Usurper",
    [
        (spawn_around_party, "p_main_party", "pt_burilgi_the_usurper"),
        (display_message, "@Burilgi the Usurper spawned"),
    ], "."),

    ("camp_hero_5", [],
    "Spawn Dread Legion",
    [
        (spawn_around_party, "p_main_party", "pt_dread_legion"),
        (display_message, "@Dread Legion spawned"),
    ], "."),

    ("camp_hero_6", [],
    "Spawn Eyegrim the Devourer",
    [
        (spawn_around_party, "p_main_party", "pt_eyegrim"),
        (display_message, "@Eyegrim the Devourer spawned"),
    ], "."),

    ("camp_hero_7", [],
    "Spawn Oswald de Fleur",
    [
        (spawn_around_party, "p_main_party", "pt_oswald"),
        (display_message, "@Oswald de Fleur spawned"),
    ], "."),

    ("camp_hero_8", [],
    "Spawn Sheik Shalavan",
    [
        (spawn_around_party, "p_main_party", "pt_shalavan"),
        (display_message, "@Sheik Shalavan spawned"),
    ], "."),

    ("camp_hero_more", [],
    "More spawns...",
    [
        (jump_to_menu, "mnu_camp_hero2"),
    ], "."),

    ("camp_hero_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_hero2", 0,
"Select an option:",
"none", 
[
    (set_spawn_radius, 2),
],
[
    ("camp_hero_9", [],
    "Spawn Wolfbode the Slayer",
    [
        (spawn_around_party, "p_main_party", "pt_wolfbode"),
        (display_message, "@Wolfbode the Slayer spawned"),
    ], "."),

    ("camp_hero_10", [],
    "Spawn Syla Uzas",
    [
        (spawn_around_party, "p_main_party", "pt_syla_uzas"),
        (display_message, "@Syla Uzas spawned"),
    ], "."),

    ("camp_hero_11", [],
    "Spawn Griffonsword",
    [
        (spawn_around_party, "p_main_party", "pt_griffonsword"),
        (display_message, "@Griffonsword spawned"),
    ], "."),

    ("camp_hero_12", [],
    "Spawn Kodan Ironsword",
    [
        (spawn_around_party, "p_main_party", "pt_ironsword"),
        (display_message, "@Kodan Ironsword spawned"),
    ], "."),

    ("camp_hero_13", [],
    "Spawn Aeldarian",
    [
        (spawn_around_party, "p_main_party", "pt_noldor_lord_1"),
        (display_message, "@Aeldarian spawned"),
    ], "."),

    ("camp_hero_14", [],
    "Spawn Ithilrandir",
    [
        (spawn_around_party, "p_main_party", "pt_noldor_lord_2"),
        (display_message, "@Ithilrandir spawned"),
    ], "."),

    ("camp_hero_15", [],
    "Spawn K'Juda the Ravager",
    [
        (spawn_around_party, "p_main_party", "pt_jatu_k_juda"),
        (display_message, "@K'Juda the Ravager spawned"),
    ], "."),

    ("camp_hero_16", [],
    "Spawn Warlord Zulkar",
    [
        (spawn_around_party, "p_main_party", "pt_jatu_zulkar"),
        (display_message, "@Warlord Zulkar spawned"),
    ], "."),

    ("camp_hero_more", [],
    "Even more spawns (POP 3.6)...",
    [
        (jump_to_menu, "mnu_camp_hero3"),
    ], "."),

    ("camp_hero2_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_hero3", 0,
"Select an option:",
"none", 
[
    (set_spawn_radius, 2),
],
[
    ("camp_hero_9", [],
    "Spawn Obrist Heynrich",
    [
        (spawn_around_party, "p_main_party", "pt_mett_obrist"),
        (display_message, "@Obrist Heynrich spawned"),
    ], "."),

    ("camp_hero_10", [],
    "Spawn Verante Kruus",
    [
        (spawn_around_party, "p_main_party", "pt_vecc_verante"),
        (display_message, "@Verante Kruus spawned"),
    ], "."),

    ("camp_hero_11", [],
    "Spawn Rufio of Barclay",
    [
        (spawn_around_party, "p_main_party", "pt_barclay_rufio"),
        (display_message, "@Rufio of Barclay spawned"),
    ], "."),

    ("camp_hero_12", [],
    "Spawn Sebastokrator Kaspax",
    [
        (spawn_around_party, "p_main_party", "pt_melitine_kaspax"),
        (display_message, "@Sebastokrator Kaspax spawned"),
    ], "."),

    ("camp_hero3_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_victory", 0,
"Select an option:",
"none", [],
[
    ("camp_victory_simple", [],
    "Simple victory screen",
    [
        (start_presentation, "prsnt_victory_screen_simple"),
    ], "."),

    ("camp_victoryold", [],
    "Old Victory screen",
    [
        (start_presentation, "prsnt_group_photo"),
    ], "."),

    ("camp_victory_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_fun", 0,
"Select an option:",
"none", 
[
    (set_spawn_radius, 2),
],
[
    ("camp_fun_village", 
    [
        (try_begin),
            (neg|eq, "$test_burn", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Burn everything: {s7}",
    [
        (store_sub, "$test_burn", 1, "$test_burn"),
        (val_clamp, "$test_burn", 0, 2),
        (try_for_range, ":var_0", "p_town_1", "p_salt_mine"),
            (try_begin),
                (eq, "$test_burn", 0),
                (party_clear_particle_systems, ":var_0"),
            (else_try),
                (try_begin),
                    (is_between, ":var_0", "p_town_1", "p_castle_1"),
                    (party_add_particle_system, ":var_0", "psys_village_fire_big"),
                (else_try),
                    (party_add_particle_system, ":var_0", "psys_map_village_fire"),
                (try_end),
            (try_end),
        (try_end),
    ], "."),

    ("camp_fun_twins", [],
    "Spawn evil twins!",
    [
        (spawn_around_party, "p_main_party", "pt_looters"),
        (assign, ":var_0", reg0),
        (call_script, "script_party_copy", ":var_0", "p_main_party"),
        (party_set_name, ":var_0", "@Evil Twins"),
        (party_set_faction, ":var_0", "fac_outlaws"),
        (party_get_icon, ":var_1", "p_main_party"),
        (party_set_icon, ":var_0", ":var_1"),
        (display_message, "@Evil twin party spawned!"),
    ], "."),

    ("camp_fun_female", [],
    "Make soldiers female!",
    [
        (try_for_range, ":var_0", "trp_farmer", "trp_town_walker_1"),
            (troop_set_type, ":var_0", 1),
        (try_end),
        (display_message, "@Soldiers' balls cut off!"),
    ], "."),

    ("camp_fun_undead", [],
    "Make soldiers undead!",
    [
        (try_for_range, ":var_0", "trp_farmer", "trp_town_walker_1"),
            (troop_set_type, ":var_0", 3),
        (try_end),
        (display_message, "@Soldiers killed and ressurected!"),
    ], "."),

    ("camp_fun_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_autoloot", 0,
"Select an option:",
"none", [],
[
    ("camp_autoloot_choose_item", 
    [
        (try_begin),
            (eq, "$test_item_type", 0),
            (assign, "$test_item_type", 1),
        (try_end),
        (try_begin),
            (eq, "$test_item_type", 1),
            (str_store_string, s3, "@Horse"),
        (else_try),
            (eq, "$test_item_type", 2),
            (str_store_string, s3, "@1-Handed"),
        (else_try),
            (eq, "$test_item_type", 3),
            (str_store_string, s3, "@2-Handed"),
        (else_try),
            (eq, "$test_item_type", 4),
            (try_begin),
                (eq, "$test_item_halberd", 0),
                (str_store_string, s3, "@Polearm - Spear"),
            (else_try),
                (str_store_string, s3, "@Polearm - Halberd"),
            (try_end),
        (else_try),
            (eq, "$test_item_type", 5),
            (str_store_string, s3, "@Arrows"),
        (else_try),
            (eq, "$test_item_type", 6),
            (str_store_string, s3, "@Bolts"),
        (else_try),
            (eq, "$test_item_type", 7),
            (str_store_string, s3, "@Shield"),
        (else_try),
            (eq, "$test_item_type", 8),
            (str_store_string, s3, "@Bow"),
        (else_try),
            (eq, "$test_item_type", 9),
            (str_store_string, s3, "@Crossbow"),
        (else_try),
            (eq, "$test_item_type", 10),
            (str_store_string, s3, "@Thrown"),
        (else_try),
            (eq, "$test_item_type", 12),
            (str_store_string, s3, "@Helmet"),
        (else_try),
            (eq, "$test_item_type", 13),
            (str_store_string, s3, "@Armor"),
        (else_try),
            (eq, "$test_item_type", 14),
            (str_store_string, s3, "@Boots"),
        (else_try),
            (eq, "$test_item_type", 15),
            (str_store_string, s3, "@Gloves"),
        (else_try),
            (str_store_string, s3, "@ERROR"),
        (try_end),
    ],
    "Change item type: {s3}",
    [
        (try_begin),
            (eq, "$test_item_type", 15),
            (assign, "$test_item_type", 1),
        (else_try),
            (eq, "$test_item_type", 10),
            (assign, "$test_item_type", 12),
        (else_try),
            (eq, "$test_item_type", 4),
            (try_begin),
                (eq, "$test_item_halberd", 0),
                (assign, "$test_item_halberd", 1),
            (else_try),
                (assign, "$test_item_halberd", 0),
                (assign, "$test_item_type", 5),
            (try_end),
        (else_try),
            (val_add, "$test_item_type", 1),
        (try_end),
    ], "."),

    ("camp_autoloot_cavalry_toggle", 
    [
        (try_begin),
            (neg|eq, "$test_cavalry_restricted", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Cavalry restriction: {s7}",
    [
        (val_clamp, "$test_cavalry_restricted", 0, 2),
        (store_sub, "$test_cavalry_restricted", 1, "$test_cavalry_restricted"),
    ], "."),

    ("camp_autoloot_item_trade", [],
    "Review/buy items",
    [
        (troop_clear_inventory, "trp_find_item_cheat"),
        (assign, ":var_0", 0),
        (try_for_range_backwards, ":var_1", 0, "itm_items_end"),
            (neg|eq, ":var_0", 96),
            (item_get_type, ":var_2", ":var_1"),
            (eq, ":var_2", "$test_item_type"),
            (this_or_next|item_slot_eq, ":var_1", 19, 0),
            (eq, "$test_cavalry_restricted", 0),
            (troop_add_items, "trp_find_item_cheat", ":var_1", 1),
            (val_add, ":var_0", 1),
        (try_end),
        (troop_sort_inventory, "trp_find_item_cheat"),
        (change_screen_trade, "trp_find_item_cheat"),
    ], "."),

    ("camp_autoloot_calc", [],
    "Calculate average and standard deviation for item attributes.",
    [
        (try_for_range, ":var_0", 9, 19),
            (str_store_string, s4, "@Not used"),
            (try_begin),
                (eq, "$test_item_type", 1),
                (try_begin),
                    (eq, ":var_0", 9),
                    (str_store_string, s4, "@Horse Charge"),
                (else_try),
                    (eq, ":var_0", 10),
                    (str_store_string, s4, "@Horse Speed"),
                (else_try),
                    (eq, ":var_0", 16),
                    (str_store_string, s4, "@Horse Maneuver"),
                (else_try),
                    (eq, ":var_0", 17),
                    (str_store_string, s4, "@Horse Armor"),
                (else_try),
                    (eq, ":var_0", 18),
                    (str_store_string, s4, "@Horse Hitpoints"),
                (try_end),
            (else_try),
                (this_or_next|eq, "$test_item_type", 2),
                (this_or_next|eq, "$test_item_type", 3),
                (eq, "$test_item_type", 4),
                (try_begin),
                    (eq, ":var_0", 9),
                    (str_store_string, s4, "@Swing Damage"),
                (else_try),
                    (eq, ":var_0", 10),
                    (str_store_string, s4, "@Thrust Damage"),
                (else_try),
                    (eq, ":var_0", 16),
                    (str_store_string, s4, "@Weapon Speed"),
                (else_try),
                    (eq, ":var_0", 17),
                    (str_store_string, s4, "@Weapon Reach"),
                (try_end),
            (else_try),
                (this_or_next|eq, "$test_item_type", 5),
                (eq, "$test_item_type", 6),
                (try_begin),
                    (eq, ":var_0", 9),
                    (str_store_string, s4, "@Missile speed"),
                (else_try),
                    (eq, ":var_0", 10),
                    (str_store_string, s4, "@Max Ammo"),
                (else_try),
                    (eq, ":var_0", 16),
                    (str_store_string, s4, "@Bonus Damage"),
                (try_end),
            (else_try),
                (eq, "$test_item_type", 7),
                (try_begin),
                    (eq, ":var_0", 9),
                    (str_store_string, s4, "@Shield Resistance"),
                (else_try),
                    (eq, ":var_0", 10),
                    (str_store_string, s4, "@Shield Speed"),
                (else_try),
                    (eq, ":var_0", 16),
                    (str_store_string, s4, "@Shield Hitpoints"),
                (else_try),
                    (eq, ":var_0", 17),
                    (str_store_string, s4, "@Shield Coverage"),
                (try_end),
            (else_try),
                (this_or_next|eq, "$test_item_type", 8),
                (this_or_next|eq, "$test_item_type", 9),
                (eq, "$test_item_type", 10),
                (try_begin),
                    (eq, ":var_0", 9),
                    (str_store_string, s4, "@Ranged Damage"),
                (else_try),
                    (eq, ":var_0", 10),
                    (str_store_string, s4, "@Reload Speed"),
                (else_try),
                    (eq, ":var_0", 16),
                    (str_store_string, s4, "@Missile Speed"),
                (try_end),
            (else_try),
                (this_or_next|eq, "$test_item_type", 12),
                (this_or_next|eq, "$test_item_type", 13),
                (this_or_next|eq, "$test_item_type", 14),
                (eq, "$test_item_type", 15),
                (try_begin),
                    (eq, ":var_0", 9),
                    (str_store_string, s4, "@Body Armor"),
                (else_try),
                    (eq, ":var_0", 10),
                    (str_store_string, s4, "@Leg Armor"),
                (else_try),
                    (eq, ":var_0", 16),
                    (str_store_string, s4, "@Head Armor"),
                (else_try),
                    (eq, ":var_0", 17),
                    (str_store_string, s4, "@Armor Weight"),
                (try_end),
            (else_try),
                (str_store_string, s4, "@ERROR"),
            (try_end),
            (assign, ":var_1", 0),
            (assign, ":var_2", 0),
            (assign, ":var_3", 0),
            (try_for_range, ":var_4", "itm_sumpter_horse", "itm_items_end"),
                (item_get_type, ":var_5", ":var_4"),
                (eq, ":var_5", "$test_item_type"),
                (this_or_next|item_slot_eq, ":var_4", 19, 0),
                (eq, "$test_cavalry_restricted", 0),
                (assign, ":var_6", 1),
                (try_begin),
                    (eq, ":var_5", 4),
                    (item_get_slot, ":var_7", ":var_4", 9),
                    (item_get_slot, ":var_8", ":var_4", 10),
                    (try_begin),
                        (eq, "$test_item_halberd", 0),
                        (gt, ":var_7", ":var_8"),
                        (assign, ":var_6", 0),
                    (else_try),
                        (eq, "$test_item_halberd", 1),
                        (gt, ":var_8", ":var_7"),
                        (assign, ":var_6", 0),
                    (try_end),
                (try_end),
                (eq, ":var_6", 1),
                (item_get_slot, ":var_9", ":var_4", ":var_0"),
                (val_add, ":var_1", ":var_9"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (gt, ":var_2", 0),
                (neg|eq, ":var_1", 0),
                (store_div, ":var_3", ":var_1", ":var_2"),
                (assign, ":var_1", 0),
                (assign, ":var_10", 0),
                (try_for_range, ":var_4", "itm_sumpter_horse", "itm_items_end"),
                    (item_get_type, ":var_5", ":var_4"),
                    (eq, ":var_5", "$test_item_type"),
                    (this_or_next|item_slot_eq, ":var_4", 19, 0),
                    (eq, "$test_cavalry_restricted", 0),
                    (assign, ":var_6", 1),
                    (try_begin),
                        (eq, ":var_5", 4),
                        (item_get_slot, ":var_7", ":var_4", 9),
                        (item_get_slot, ":var_8", ":var_4", 10),
                        (try_begin),
                            (eq, "$test_item_halberd", 0),
                            (gt, ":var_7", ":var_8"),
                            (assign, ":var_6", 0),
                        (else_try),
                            (eq, "$test_item_halberd", 1),
                            (gt, ":var_8", ":var_7"),
                            (assign, ":var_6", 0),
                        (try_end),
                    (try_end),
                    (eq, ":var_6", 1),
                    (item_get_slot, ":var_9", ":var_4", ":var_0"),
                    (val_sub, ":var_9", ":var_3"),
                    (val_mul, ":var_9", ":var_9"),
                    (val_add, ":var_1", ":var_9"),
                (try_end),
                (store_div, ":var_10", ":var_1", ":var_2"),
                (convert_to_fixed_point, ":var_10"),
                (store_sqrt, ":var_10", ":var_10"),
                (convert_from_fixed_point, ":var_10"),
                (assign, reg0, ":var_3"),
                (assign, reg1, ":var_10"),
                (assign, reg2, ":var_2"),
                (display_message, "@{s4}: Average: {reg0}, St.dev.: {reg1}, Count: {reg2}", 0xAAAA),
            (try_end),
        (try_end),
    ], "."),

    ("camp_autoloot_score", [],
    "Print all autoloot scores",
    [
        (display_message, "@Printing scores...", 0xAAAA),
        (try_for_range, ":var_0", "itm_sumpter_horse", "itm_items_end"),
            (item_get_type, ":var_1", ":var_0"),
            (eq, ":var_1", "$test_item_type"),
            (this_or_next|item_slot_eq, ":var_0", 19, 0),
            (eq, "$test_cavalry_restricted", 0),
            (assign, ":var_2", 1),
            (try_begin),
                (eq, ":var_1", 4),
                (item_get_slot, ":var_3", ":var_0", 9),
                (item_get_slot, ":var_4", ":var_0", 10),
                (assign, ":var_5", 0),
                (try_begin),
                    (eq, "$test_item_halberd", 0),
                    (assign, ":var_5", 2),
                    (gt, ":var_3", ":var_4"),
                    (assign, ":var_2", 0),
                (else_try),
                    (eq, "$test_item_halberd", 1),
                    (assign, ":var_5", 1),
                    (gt, ":var_4", ":var_3"),
                    (assign, ":var_2", 0),
                (try_end),
            (try_end),
            (eq, ":var_2", 1),
            (call_script, "script_get_item_value_with_imod", ":var_0", 0, ":var_5"),
            (str_store_item_name, s10, ":var_0"),
            (display_message, "@{reg0}: {s10}"),
        (try_end),
    ], "."),

    ("camp_autoloot_top20", [],
    "Print top 20 autoloot scores",
    [
        (assign, ":var_0", 20),
        (try_for_range, ":var_1", 0, ":var_0"),
            (troop_set_slot, "trp_temp_array_a", ":var_1", 0),
            (troop_set_slot, "trp_temp_array_b", ":var_1", 0),
        (try_end),
        (try_for_range, ":var_2", "itm_sumpter_horse", "itm_items_end"),
            (item_get_type, ":var_3", ":var_2"),
            (eq, ":var_3", "$test_item_type"),
            (this_or_next|item_slot_eq, ":var_2", 19, 0),
            (eq, "$test_cavalry_restricted", 0),
            (assign, ":var_4", 0),
            (try_begin),
                (eq, ":var_3", 4),
                (try_begin),
                    (eq, "$test_item_halberd", 0),
                    (assign, ":var_4", 2),
                (else_try),
                    (assign, ":var_4", 1),
                (try_end),
            (try_end),
            (call_script, "script_get_item_value_with_imod", ":var_2", 0, ":var_4"),
            (assign, ":var_5", reg0),
            (assign, ":var_6", 0),
            (try_for_range, ":var_1", 0, ":var_0"),
                (eq, ":var_6", 0),
                (try_begin),
                    (troop_get_slot, ":var_7", "trp_temp_array_a", ":var_1"),
                    (gt, ":var_5", ":var_7"),
                    (assign, ":var_6", 1),
                    (assign, ":var_8", ":var_5"),
                    (assign, ":var_9", ":var_2"),
                    (try_for_range, ":var_10", ":var_1", ":var_0"),
                        (troop_get_slot, ":var_11", "trp_temp_array_a", ":var_10"),
                        (troop_get_slot, ":var_12", "trp_temp_array_b", ":var_10"),
                        (troop_set_slot, "trp_temp_array_a", ":var_10", ":var_8"),
                        (troop_set_slot, "trp_temp_array_b", ":var_10", ":var_9"),
                        (assign, ":var_8", ":var_11"),
                        (assign, ":var_9", ":var_12"),
                    (try_end),
                (try_end),
            (try_end),
        (try_end),
        (try_for_range, ":var_1", 0, ":var_0"),
            (troop_get_slot, reg1, "trp_temp_array_a", ":var_1"),
            (troop_get_slot, ":var_2", "trp_temp_array_b", ":var_1"),
            (neg|eq, reg1, 0),
            (store_add, reg0, ":var_1", 1),
            (str_store_item_name, s10, ":var_2"),
            (display_message, "@{reg0}. {reg1}: {s10}", 0xFFFF00),
        (try_end),
    ], "."),

    ("camp_autoloot_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_companion", 0,
"Select an option:",
"none", [],
[
    ("camp_comp_recruit", [],
    "Recruit all 20 companions",
    [
        (party_add_members, "p_main_party", "trp_npc_adonja", 1),
        (party_add_members, "p_main_party", "trp_npc_leslie", 1),
        (party_add_members, "p_main_party", "trp_npc_ansen", 1),
        (party_add_members, "p_main_party", "trp_npc_riva", 1),
        (party_add_members, "p_main_party", "trp_npc_kassim", 1),
        (party_add_members, "p_main_party", "trp_npc_lethaldiran", 1),
        (party_add_members, "p_main_party", "trp_npc_jocelyn", 1),
        (party_add_members, "p_main_party", "trp_npc_alistair", 1),
        (party_add_members, "p_main_party", "trp_npc_rayne", 1),
        (party_add_members, "p_main_party", "trp_npc_julia", 1),
        (party_add_members, "p_main_party", "trp_npc_frederick", 1),
        (party_add_members, "p_main_party", "trp_npc_ediz", 1),
        (party_add_members, "p_main_party", "trp_npc_sara", 1),
        (party_add_members, "p_main_party", "trp_npc_donavan", 1),
        (party_add_members, "p_main_party", "trp_npc_diev", 1),
        (party_add_members, "p_main_party", "trp_npc_alyssa", 1),
        (party_add_members, "p_main_party", "trp_npc_roland", 1),
        (party_add_members, "p_main_party", "trp_npc_kaverra", 1),
        (party_add_members, "p_main_party", "trp_npc_sigismund", 1),
        (party_add_members, "p_main_party", "trp_npc_boadice", 1),
        (try_for_range, ":var_0", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (troop_set_slot, ":var_0", slot_troop_occupation, 5),
            (troop_set_slot, ":var_0", slot_troop_cur_center, -1),
            (troop_set_auto_equip, ":var_0", 0),
        (try_end),
        (display_message, "@All 20 companions recruited"),
    ], "."),

    ("camp_comp_linked", [],
    "Random linked conversation",
    [
        (assign, ":var_0", 0),
        (assign, ":var_1", 0),
        (try_for_range, ":var_2", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (main_party_has_troop, ":var_2"),
            (neg|troop_is_wounded, ":var_2"),
            (troop_get_slot, ":var_3", ":var_2", 79),
            (troop_get_slot, ":var_4", ":var_2", slot_troop_personalityclash_object),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (main_party_has_troop, ":var_4"),
                (neg|troop_is_wounded, ":var_4"),
                (store_and, ":var_0", ":var_3", 1),
                (eq, ":var_0", 0),
                (val_add, ":var_1", 1),
            (try_end),
            (troop_get_slot, ":var_4", ":var_2", slot_troop_personalityclash2_object),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (main_party_has_troop, ":var_4"),
                (neg|troop_is_wounded, ":var_4"),
                (store_and, ":var_0", ":var_3", 2),
                (eq, ":var_0", 0),
                (val_add, ":var_1", 1),
            (try_end),
            (troop_get_slot, ":var_4", ":var_2", slot_troop_personalitymatch_object),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (main_party_has_troop, ":var_4"),
                (neg|troop_is_wounded, ":var_4"),
                (store_and, ":var_0", ":var_3", 4),
                (eq, ":var_0", 0),
                (val_add, ":var_1", 1),
            (try_end),
        (try_end),
        (gt, ":var_1", 0),
        (store_random_in_range, ":var_5", 0, ":var_1"),
        (store_add, reg0, ":var_5", 1),
        (assign, reg1, ":var_1"),
        (display_message, "@Conversation #{reg0} chosen out of {reg1} total."),
        (assign, ":var_6", 0),
        (try_for_range, ":var_2", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (ge, ":var_5", 0),
            (troop_get_slot, ":var_3", ":var_2", 79),
            (troop_get_slot, ":var_4", ":var_2", slot_troop_personalityclash_object),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (val_add, ":var_6", 1),
            (try_end),
            (main_party_has_troop, ":var_2"),
            (neg|troop_is_wounded, ":var_2"),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (main_party_has_troop, ":var_4"),
                (neg|troop_is_wounded, ":var_4"),
                (store_and, ":var_0", ":var_3", 1),
                (eq, ":var_0", 0),
                (try_begin),
                    (eq, ":var_5", 0),
                    (val_or, ":var_3", 1),
                    (troop_set_slot, ":var_2", 79, ":var_3"),
                    (assign, ":var_7", ":var_2"),
                    (assign, ":var_8", ":var_4"),
                    (try_begin),
                        (this_or_next|eq, ":var_6", 1),
                        (this_or_next|eq, ":var_6", 2),
                        (this_or_next|eq, ":var_6", 6),
                        (eq, ":var_6", 10),
                        (assign, ":var_7", ":var_4"),
                        (assign, ":var_8", ":var_2"),
                    (try_end),
                    (assign, "$npc_dialog_partner", ":var_8"),
                    (start_map_conversation, ":var_7"),
                    (change_screen_map),
                (try_end),
                (val_sub, ":var_5", 1),
            (try_end),
        (try_end),
        (assign, ":var_6", 0),
        (try_for_range, ":var_2", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (ge, ":var_5", 0),
            (troop_get_slot, ":var_3", ":var_2", 79),
            (troop_get_slot, ":var_4", ":var_2", slot_troop_personalityclash2_object),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (val_add, ":var_6", 1),
            (try_end),
            (main_party_has_troop, ":var_2"),
            (neg|troop_is_wounded, ":var_2"),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (main_party_has_troop, ":var_4"),
                (neg|troop_is_wounded, ":var_4"),
                (store_and, ":var_0", ":var_3", 2),
                (eq, ":var_0", 0),
                (try_begin),
                    (eq, ":var_5", 0),
                    (val_or, ":var_3", 2),
                    (troop_set_slot, ":var_2", 79, ":var_3"),
                    (assign, ":var_7", ":var_2"),
                    (assign, ":var_8", ":var_4"),
                    (try_begin),
                        (this_or_next|eq, ":var_6", 1),
                        (this_or_next|eq, ":var_6", 3),
                        (this_or_next|eq, ":var_6", 4),
                        (this_or_next|eq, ":var_6", 6),
                        (eq, ":var_6", 9),
                        (assign, ":var_7", ":var_4"),
                        (assign, ":var_8", ":var_2"),
                    (try_end),
                    (assign, "$npc_dialog_partner", ":var_8"),
                    (start_map_conversation, ":var_7"),
                    (change_screen_map),
                (try_end),
                (val_sub, ":var_5", 1),
            (try_end),
        (try_end),
        (assign, ":var_6", 0),
        (try_for_range, ":var_2", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (ge, ":var_5", 0),
            (troop_get_slot, ":var_3", ":var_2", 79),
            (troop_get_slot, ":var_4", ":var_2", slot_troop_personalitymatch_object),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (val_add, ":var_6", 1),
            (try_end),
            (main_party_has_troop, ":var_2"),
            (neg|troop_is_wounded, ":var_2"),
            (try_begin),
                (gt, ":var_4", ":var_2"),
                (main_party_has_troop, ":var_4"),
                (neg|troop_is_wounded, ":var_4"),
                (store_and, ":var_0", ":var_3", 4),
                (eq, ":var_0", 0),
                (try_begin),
                    (eq, ":var_5", 0),
                    (val_or, ":var_3", 4),
                    (troop_set_slot, ":var_2", 79, ":var_3"),
                    (assign, ":var_7", ":var_2"),
                    (assign, ":var_8", ":var_4"),
                    (try_begin),
                        (this_or_next|eq, ":var_6", 1),
                        (this_or_next|eq, ":var_6", 2),
                        (this_or_next|eq, ":var_6", 3),
                        (this_or_next|eq, ":var_6", 4),
                        (this_or_next|eq, ":var_6", 8),
                        (this_or_next|eq, ":var_6", 9),
                        (eq, ":var_6", 10),
                        (assign, ":var_7", ":var_4"),
                        (assign, ":var_8", ":var_2"),
                    (try_end),
                    (assign, "$npc_dialog_partner", ":var_8"),
                    (start_map_conversation, ":var_7"),
                    (change_screen_map),
                (try_end),
                (val_sub, ":var_5", 1),
            (try_end),
        (try_end),
    ], "."),

    ("camp_comp_toplayer", [],
    "Random remark to player",
    [
        (assign, ":var_0", 0),
        (assign, ":var_1", 0),
        (try_for_range, ":var_2", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (main_party_has_troop, ":var_2"),
            (neg|troop_is_wounded, ":var_2"),
            (troop_get_slot, ":var_3", ":var_2", 79),
            (store_and, ":var_0", ":var_3", 8),
            (eq, ":var_0", 0),
            (assign, ":var_4", 0),
            (try_begin),
                (eq, ":var_2", "trp_npc_adonja"),
                (neg|main_party_has_troop, "trp_npc_ansen"),
            (else_try),
                (eq, ":var_2", "trp_npc_ediz"),
                (neg|main_party_has_troop, "trp_npc_rayne"),
            (else_try),
                (eq, ":var_2", "trp_npc_jocelyn"),
                (neg|main_party_has_troop, "trp_npc_alistair"),
            (else_try),
                (eq, ":var_2", "trp_npc_rayne"),
                (neg|main_party_has_troop, "trp_npc_boadice"),
            (else_try),
                (eq, ":var_2", "trp_npc_riva"),
                (neg|main_party_has_troop, "trp_npc_kassim"),
            (else_try),
                (eq, ":var_2", "trp_npc_leslie"),
                (neg|main_party_has_troop, "trp_npc_diev"),
            (else_try),
                (eq, ":var_2", "trp_npc_diev"),
                (neg|main_party_has_troop, "trp_npc_leslie"),
            (else_try),
                (assign, ":var_4", 1),
            (try_end),
            (eq, ":var_4", 1),
            (val_add, ":var_1", 1),
        (try_end),
        (gt, ":var_1", 0),
        (assign, ":var_5", -1),
        (store_random_in_range, ":var_6", 0, ":var_1"),
        (store_add, reg0, ":var_6", 1),
        (assign, reg1, ":var_1"),
        (display_message, "@Conversation #{reg0} chosen out of {reg1} total."),
        (try_for_range, ":var_2", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (ge, ":var_6", 0),
            (main_party_has_troop, ":var_2"),
            (neg|troop_is_wounded, ":var_2"),
            (troop_get_slot, ":var_3", ":var_2", 79),
            (store_and, ":var_0", ":var_3", 8),
            (eq, ":var_0", 0),
            (assign, ":var_4", 0),
            (try_begin),
                (eq, ":var_2", "trp_npc_adonja"),
                (neg|main_party_has_troop, "trp_npc_ansen"),
            (else_try),
                (eq, ":var_2", "trp_npc_ediz"),
                (neg|main_party_has_troop, "trp_npc_rayne"),
            (else_try),
                (eq, ":var_2", "trp_npc_jocelyn"),
                (neg|main_party_has_troop, "trp_npc_alistair"),
            (else_try),
                (eq, ":var_2", "trp_npc_rayne"),
                (neg|main_party_has_troop, "trp_npc_boadice"),
            (else_try),
                (eq, ":var_2", "trp_npc_riva"),
                (neg|main_party_has_troop, "trp_npc_kassim"),
            (else_try),
                (eq, ":var_2", "trp_npc_leslie"),
                (neg|main_party_has_troop, "trp_npc_diev"),
            (else_try),
                (eq, ":var_2", "trp_npc_diev"),
                (neg|main_party_has_troop, "trp_npc_leslie"),
            (else_try),
                (assign, ":var_4", 1),
            (try_end),
            (eq, ":var_4", 1),
            (try_begin),
                (eq, ":var_6", 0),
                (val_or, ":var_3", 8),
                (troop_set_slot, ":var_2", 79, ":var_3"),
                (assign, ":var_5", ":var_2"),
            (try_end),
            (val_sub, ":var_6", 1),
        (try_end),
        (assign, "$npc_dialog_partner", -1),
        (start_map_conversation, ":var_5"),
        (change_screen_map),
    ], "."),

    ("camp_comp_back", [],
    "Back to main test menu.",
    [
        (jump_to_menu, "mnu_camp_vader"),
    ], "."),

]),

("camp_action", 0,
"Choose an action:",
"none", [],
[
    ("camp_recruit_prisoners", 
    [
        (troops_can_join, 1),
        (store_current_hours, ":var_0"),
        (val_sub, ":var_0", 24),
        (gt, ":var_0", "$g_prisoner_recruit_last_time"),
        (try_begin),
            (gt, "$g_prisoner_recruit_last_time", 0),
            (assign, "$g_prisoner_recruit_troop_id", 0),
            (assign, "$g_prisoner_recruit_size", 0),
            (assign, "$g_prisoner_recruit_last_time", 0),
        (try_end),
        (neg|check_quest_active, "qst_order_challenge"),
    ],
    "Recruit some of your prisoners to your party.",
    [
        (jump_to_menu, "mnu_camp_recruit_prisoners"),
    ], "."),

    ("action_read_book", [],
    "Select a book to read.",
    [
        (jump_to_menu, "mnu_camp_action_read_book"),
    ], "."),

    ("action_rename_party", [],
    "Rename your party.",
    [
        (start_presentation, "prsnt_name_party"),
    ], "."),

    ("action_rename_kingdom", 
    [
        (eq, "$players_kingdom_name_set", 1),
        (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, 0),
        (faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
    ],
    "Rename your kingdom.",
    [
        (start_presentation, "prsnt_name_kingdom"),
    ], "."),

    ("action_rename_order", 
    [
        (eq, "$players_order_name_set", 1),
    ],
    "Rename your Order.",
    [
        (jump_to_menu, "mnu_auto_name_order"),
        (assign, "$menu_control", -1),
    ], "."),

    ("action_modify_banner", 
    [
        (troop_get_slot, ":var_0", "trp_player", slot_troop_banner_scene_prop),
        (gt, ":var_0", 0),
    ],
    "Modify your banner.",
    [
        (start_presentation, "prsnt_banner_selection"),
    ], "."),

    ("action_retire", [],
    "Retire from adventuring.",
    [
        (jump_to_menu, "mnu_retirement_verify"),
    ], "."),

    ("camp_action_4", [],
    "Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("camp_recruit_prisoners", 0,
"You offer your prisoners freedom if they agree to join you as soldiers. {s18}",
"none", 
[
    (assign, ":var_0", 0),
    (party_get_num_prisoner_stacks, ":var_1", "p_main_party"),
    (assign, ":var_2", 0),
    (assign, ":var_3", 0),
    (try_for_range, ":var_4", 0, ":var_1"),
        (party_prisoner_stack_get_troop_id, ":var_5", "p_main_party", ":var_4"),
        (neg|troop_is_hero, ":var_5"),
        (store_character_level, ":var_6", ":var_5"),
        (try_begin),
            (neg|ge, ":var_6", 41),
            (neg|eq, ":var_5", "trp_noldor_warrior"),
            (neg|eq, ":var_5", "trp_noldor_ranger"),
            (try_begin),
                (troop_get_type, ":var_7", ":var_5"),
                (neg|eq, ":var_7", 3),
                (val_add, ":var_0", 1),
            (else_try),
                (val_add, ":var_3", 1),
            (try_end),
        (else_try),
            (val_add, ":var_2", 1),
        (try_end),
    (try_end),
    (try_begin),
        (eq, ":var_0", 0),
        (eq, ":var_2", 0),
        (eq, ":var_3", 0),
        (jump_to_menu, "mnu_camp_no_prisoners"),
    (else_try),
        (eq, "$g_prisoner_recruit_troop_id", 0),
        (store_current_hours, "$g_prisoner_recruit_last_time"),
        (store_random_in_range, ":var_8", 0, 100),
        (store_skill_level, ":var_9", "skl_persuasion", "trp_player"),
        (store_sub, ":var_10", 15, ":var_9"),
        (val_mul, ":var_10", 4),
        (try_begin),
            (neg|ge, ":var_8", ":var_10"),
            (assign, "$g_prisoner_recruit_troop_id", -7),
        (else_try),
            (assign, ":var_0", 0),
            (party_get_num_prisoner_stacks, ":var_1", "p_main_party"),
            (try_for_range, ":var_4", 0, ":var_1"),
                (party_prisoner_stack_get_troop_id, ":var_5", "p_main_party", ":var_4"),
                (neg|troop_is_hero, ":var_5"),
                (store_character_level, ":var_6", ":var_5"),
                (try_begin),
                    (neg|ge, ":var_6", 41),
                    (neg|eq, ":var_5", "trp_noldor_warrior"),
                    (neg|eq, ":var_5", "trp_noldor_ranger"),
                    (try_begin),
                        (troop_get_type, ":var_7", ":var_5"),
                        (neg|eq, ":var_7", 3),
                        (val_add, ":var_0", 1),
                    (try_end),
                (try_end),
            (try_end),
            (store_random_in_range, ":var_11", 0, ":var_0"),
            (try_for_range, ":var_4", 0, ":var_1"),
                (party_prisoner_stack_get_troop_id, ":var_5", "p_main_party", ":var_4"),
                (neg|troop_is_hero, ":var_5"),
                (store_character_level, ":var_6", ":var_5"),
                (try_begin),
                    (neg|ge, ":var_6", 41),
                    (neg|eq, ":var_5", "trp_noldor_warrior"),
                    (neg|eq, ":var_5", "trp_noldor_ranger"),
                    (try_begin),
                        (troop_get_type, ":var_7", ":var_5"),
                        (neg|eq, ":var_7", 3),
                        (val_sub, ":var_11", 1),
                        (neg|ge, ":var_11", 0),
                        (assign, ":var_1", 0),
                        (assign, "$g_prisoner_recruit_troop_id", ":var_5"),
                        (party_prisoner_stack_get_size, "$g_prisoner_recruit_size", "p_main_party", ":var_4"),
                    (try_end),
                (try_end),
            (try_end),
        (try_end),
        (try_begin),
            (gt, "$g_prisoner_recruit_troop_id", 0),
            (party_get_free_companions_capacity, ":var_12", "p_main_party"),
            (val_min, "$g_prisoner_recruit_size", ":var_12"),
            (assign, reg1, "$g_prisoner_recruit_size"),
            (gt, "$g_prisoner_recruit_size", 0),
            (try_begin),
                (gt, "$g_prisoner_recruit_size", 1),
                (assign, reg2, 1),
            (else_try),
                (assign, reg2, 0),
            (try_end),
            (str_store_troop_name_by_count, s1, "$g_prisoner_recruit_troop_id", "$g_prisoner_recruit_size"),
            (str_store_string, s18, "@{reg1} {s1} {reg2?accept:accepts} the offer."),
        (else_try),
            (str_store_string, s18, "@No one accepts the offer."),
            (try_begin),
                (ge, ":var_2", 1),
                (assign, reg1, ":var_2"),
                (store_sub, reg2, ":var_2", 1),
                (str_store_string, s18, "@{s18}^^ There {reg2?are:is} {reg1} {reg2?types:type} of Elite troops present that cannot be persuaded to join your cause."),
            (try_end),
            (try_begin),
                (ge, ":var_3", 1),
                (assign, reg1, ":var_3"),
                (store_sub, reg2, ":var_3", 1),
                (str_store_string, s18, "@{s18}^^ There {reg2?are:is} {reg1} {reg2?types:type} of undead troops present that cannot be persuaded to join your cause."),
            (try_end),
        (try_end),
    (try_end),
],
[
    ("camp_recruit_prisoners_accept", 
    [
        (gt, "$g_prisoner_recruit_troop_id", 0),
    ],
    "Take them.",
    [
        (remove_troops_from_prisoners, "$g_prisoner_recruit_troop_id", "$g_prisoner_recruit_size"),
        (party_add_members, "p_main_party", "$g_prisoner_recruit_troop_id", "$g_prisoner_recruit_size"),
        (store_mul, ":var_0", -3, "$g_prisoner_recruit_size"),
        (call_script, "script_change_player_party_morale", ":var_0"),
        (jump_to_menu, "mnu_camp"),
    ], "."),

    ("camp_recruit_prisoners_reject", 
    [
        (gt, "$g_prisoner_recruit_troop_id", 0),
    ],
    "Reject them.",
    [
        (jump_to_menu, "mnu_camp"),
        (assign, "$g_prisoner_recruit_troop_id", 0),
        (assign, "$g_prisoner_recruit_size", 0),
    ], "."),

    ("continue", 
    [
        (neg|gt, "$g_prisoner_recruit_troop_id", 0),
    ],
    "Go back.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("camp_no_prisoners", 0,
"You have no prisoners to recruit from.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("camp_action_read_book", 0,
"Choose a book to read:",
"none", [],
[
    ("action_read_book_1", 
    [
        (player_has_item, "itm_book_tactics"),
        (item_slot_eq, "itm_book_tactics", slot_item_book_read, 0),
        (str_store_item_name, s1, "itm_book_tactics"),
    ],
    "{s1}.",
    [
        (assign, "$temp", "itm_book_tactics"),
        (jump_to_menu, "mnu_camp_action_read_book_start"),
    ], "."),

    ("action_read_book_2", 
    [
        (player_has_item, "itm_book_persuasion"),
        (item_slot_eq, "itm_book_persuasion", slot_item_book_read, 0),
        (str_store_item_name, s1, "itm_book_persuasion"),
    ],
    "{s1}.",
    [
        (assign, "$temp", "itm_book_persuasion"),
        (jump_to_menu, "mnu_camp_action_read_book_start"),
    ], "."),

    ("action_read_book_3", 
    [
        (player_has_item, "itm_book_leadership"),
        (item_slot_eq, "itm_book_leadership", slot_item_book_read, 0),
        (str_store_item_name, s1, "itm_book_leadership"),
    ],
    "{s1}.",
    [
        (assign, "$temp", "itm_book_leadership"),
        (jump_to_menu, "mnu_camp_action_read_book_start"),
    ], "."),

    ("action_read_book_4", 
    [
        (player_has_item, "itm_book_intelligence"),
        (item_slot_eq, "itm_book_intelligence", slot_item_book_read, 0),
        (str_store_item_name, s1, "itm_book_intelligence"),
    ],
    "{s1}.",
    [
        (assign, "$temp", "itm_book_intelligence"),
        (jump_to_menu, "mnu_camp_action_read_book_start"),
    ], "."),

    ("action_read_book_5", 
    [
        (player_has_item, "itm_book_trade"),
        (item_slot_eq, "itm_book_trade", slot_item_book_read, 0),
        (str_store_item_name, s1, "itm_book_trade"),
    ],
    "{s1}.",
    [
        (assign, "$temp", "itm_book_trade"),
        (jump_to_menu, "mnu_camp_action_read_book_start"),
    ], "."),

    ("action_read_book_6", 
    [
        (player_has_item, "itm_book_weapon_mastery"),
        (item_slot_eq, "itm_book_weapon_mastery", slot_item_book_read, 0),
        (str_store_item_name, s1, "itm_book_weapon_mastery"),
    ],
    "{s1}.",
    [
        (assign, "$temp", "itm_book_weapon_mastery"),
        (jump_to_menu, "mnu_camp_action_read_book_start"),
    ], "."),

    ("action_read_book_7", 
    [
        (player_has_item, "itm_book_engineering"),
        (item_slot_eq, "itm_book_engineering", slot_item_book_read, 0),
        (str_store_item_name, s1, "itm_book_engineering"),
    ],
    "{s1}.",
    [
        (assign, "$temp", "itm_book_engineering"),
        (jump_to_menu, "mnu_camp_action_read_book_start"),
    ], "."),

    ("camp_action_4", [],
    "Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("camp_action_read_book_start", 0,
"{s1}",
"none", 
[
    (assign, ":var_0", "$temp"),
    (str_store_item_name, s2, ":var_0"),
    (try_begin),
        (store_attribute_level, ":var_1", "trp_player", ca_intelligence),
        (item_get_slot, ":var_2", ":var_0", slot_item_intelligence_requirement),
        (neg|gt, ":var_2", ":var_1"),
        (str_store_string, s1, "@You start reading {s2}. After a few pages, you feel you could learn a lot from this book. You decide to keep it close by and read whenever you have the time."),
        (assign, "$g_player_reading_book", ":var_0"),
    (else_try),
        (str_store_string, s1, "@You flip through the pages of {s2}, but you find the text confusing and difficult to follow. Try as you might, it soon gives you a headache, and you're forced to give up the attempt."),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("retirement_verify", 0,
"You are at day {reg0}. Your current luck is {reg1}. Are you sure you want to retire?",
"none", 
[
    (store_current_day, reg0),
    (assign, reg1, "$g_player_luck"),
],
[
    ("retire_yes", [],
    "Yes.",
    [
        (start_presentation, "prsnt_retirement"),
    ], "."),

    ("retire_no", [],
    "No.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("end_game", 0,
"The decision is made, and you resolve to give up your adventurer's life and settle down. You sell off your weapons and armour, gather up all your money, and ride off into the sunset....",
"none", [],
[
    ("end_game_bye", [],
    "Farewell.",
    [
        (change_screen_quit),
    ], "."),

]),

("game_options", 0,
"Click on an option to toggle:",
"none", [],
[
    ("game_options_companions", 
    [
        (try_begin),
            (neg|eq, "$g_option_companion_dialogs", 0),
            (str_store_string, s7, "@All"),
        (else_try),
            (str_store_string, s7, "@Few"),
        (try_end),
    ],
    "Play companion dialogs: {s7}",
    [
        (store_sub, "$g_option_companion_dialogs", 1, "$g_option_companion_dialogs"),
        (val_clamp, "$g_option_companion_dialogs", 0, 2),
    ], "."),

    ("game_options_killcount", 
    [
        (try_begin),
            (neg|eq, "$g_option_show_killcount", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Show battle kill count: {s7}",
    [
        (store_sub, "$g_option_show_killcount", 1, "$g_option_show_killcount"),
        (val_clamp, "$g_option_show_killcount", 0, 2),
    ], "."),

    ("game_options_news", 
    [
        (try_begin),
            (neg|eq, "$g_option_important_news", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Important news only: {s7}",
    [
        (store_sub, "$g_option_important_news", 1, "$g_option_important_news"),
        (val_clamp, "$g_option_important_news", 0, 2),
    ], "."),

    ("game_options_formations", 
    [
        (try_begin),
            (neg|eq, "$g_option_formations", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Battle formations: {s7}",
    [
        (store_sub, "$g_option_formations", 1, "$g_option_formations"),
        (val_clamp, "$g_option_formations", 0, 2),
    ], "."),

    ("game_options_routing", 
    [
        (try_begin),
            (neg|eq, "$g_option_routing", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Disable troop routing: {s7}",
    [
        (store_sub, "$g_option_routing", 1, "$g_option_routing"),
        (val_clamp, "$g_option_routing", 0, 2),
    ], "."),

    ("game_options_lord_no_land", 
    [
        (try_begin),
            (neg|eq, "$g_option_lord_no_land", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Lords never bring centers when joining player faction: {s7}",
    [
        (store_sub, "$g_option_lord_no_land", 1, "$g_option_lord_no_land"),
        (val_clamp, "$g_option_lord_no_land", 0, 2),
    ], "."),

    ("game_options_no_defections", 
    [
        (try_begin),
            (neg|eq, "$g_option_no_defections", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "No auto-defections: {s7}",
    [
        (store_sub, "$g_option_no_defections", 1, "$g_option_no_defections"),
        (val_clamp, "$g_option_no_defections", 0, 2),
    ], "."),

    ("game_options_mini_map", 
    [
        (try_begin),
            (neg|eq, "$g_option_show_minimap", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Show battle mini map: {s7}",
    [
        (val_clamp, "$g_option_show_minimap", 0, 2),
        (val_sub, "$g_option_show_minimap", 1),
        (val_abs, "$g_option_show_minimap"),
    ], "."),

    ("game_options_horse_archer_ai", 
    [
        (try_begin),
            (neg|eq, "$g_option_horse_archer_ai", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Enhance horse archer's AI: {s7}",
    [
        (val_clamp, "$g_option_horse_archer_ai", 0, 2),
        (val_sub, "$g_option_horse_archer_ai", 1),
        (val_abs, "$g_option_horse_archer_ai"),
    ], "."),

    ("game_options_use_spearwall", 
    [
        (try_begin),
            (neg|eq, "$g_option_use_spearwall", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Use spear brace: {s7}",
    [
        (val_clamp, "$g_option_use_spearwall", 0, 2),
        (val_sub, "$g_option_use_spearwall", 1),
        (val_abs, "$g_option_use_spearwall"),
    ], "."),

    ("game_option_shield_bash", 
    [
        (try_begin),
            (neg|eq, "$g_option_use_shield_bash", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Enable shield bash: {s7}",
    [
        (val_clamp, "$g_option_use_shield_bash", 0, 2),
        (val_sub, "$g_option_use_shield_bash", 1),
        (val_abs, "$g_option_use_shield_bash"),
    ], "."),

    ("game_option_show_ally_hp_bar", 
    [
        (try_begin),
            (neg|eq, "$g_hp_bar_ally", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Enable ally hp bar: {s7}",
    [
        (val_clamp, "$g_hp_bar_ally", 0, 2),
        (val_sub, "$g_hp_bar_ally", 1),
        (val_abs, "$g_hp_bar_ally"),
        (try_begin),
            (eq, "$g_hp_bar_dis_limit", 0),
            (assign, "$g_hp_bar_dis_limit", 30),
        (try_end),
    ], "."),

    ("game_option_show_enemy_hp_bar", 
    [
        (try_begin),
            (neg|eq, "$g_hp_bar_enemy", 0),
            (str_store_string, s7, "@ON"),
        (else_try),
            (str_store_string, s7, "@OFF"),
        (try_end),
    ],
    "Enable enemy hp bar: {s7}",
    [
        (val_clamp, "$g_hp_bar_enemy", 0, 2),
        (val_sub, "$g_hp_bar_enemy", 1),
        (val_abs, "$g_hp_bar_enemy"),
        (try_begin),
            (eq, "$g_hp_bar_dis_limit", 0),
            (assign, "$g_hp_bar_dis_limit", 30),
        (try_end),
    ], "."),

    ("game_options_back", [],
    "Back to camp menu.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("cattle_herd", 4096,
"You encounter a herd of cattle.",
"none", 
[
    (play_sound, "snd_cow_moo"),
    (set_background_mesh, "mesh_pic_cattle"),
],
[
    ("cattle_drive_away", [],
    "Drive the cattle onward.",
    [
        (party_set_slot, "$g_encountered_party", slot_town_lord, 1),
        (party_set_ai_behavior, "$g_encountered_party", 10),
        (party_set_ai_object, "$g_encountered_party", "p_main_party"),
        (change_screen_return),
    ], "."),

    ("cattle_stop", [],
    "Bring the herd to a stop.",
    [
        (party_set_slot, "$g_encountered_party", slot_town_lord, 0),
        (party_set_ai_behavior, "$g_encountered_party", 0),
        (change_screen_return),
    ], "."),

    ("cattle_kill", 
    [
        (assign, ":var_0", 1),
        (try_begin),
            (check_quest_active, "qst_move_cattle_herd"),
            (quest_slot_eq, "qst_move_cattle_herd", 8, "$g_encountered_party"),
            (assign, ":var_0", 0),
        (try_end),
        (eq, ":var_0", 1),
    ],
    "Slaughter some of the animals.",
    [
        (jump_to_menu, "mnu_cattle_herd_kill"),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (change_screen_return),
    ], "."),

]),

("cattle_herd_kill", 0,
"How many animals do you want to slaughter?",
"none", 
[
    (party_get_num_companions, reg5, "$g_encountered_party"),
],
[
    ("cattle_kill_1", 
    [
        (ge, reg5, 1),
    ],
    "One.",
    [
        (call_script, "script_kill_cattle_from_herd", "$g_encountered_party", 1),
        (jump_to_menu, "mnu_cattle_herd_kill_end"),
        (change_screen_loot, "trp_temp_troop"),
        (play_sound, "snd_cow_slaughter"),
    ], "."),

    ("cattle_kill_2", 
    [
        (ge, reg5, 2),
    ],
    "Two.",
    [
        (call_script, "script_kill_cattle_from_herd", "$g_encountered_party", 2),
        (jump_to_menu, "mnu_cattle_herd_kill_end"),
        (change_screen_loot, "trp_temp_troop"),
        (play_sound, "snd_cow_slaughter"),
    ], "."),

    ("cattle_kill_3", 
    [
        (ge, reg5, 3),
    ],
    "Three.",
    [
        (call_script, "script_kill_cattle_from_herd", "$g_encountered_party", 3),
        (jump_to_menu, "mnu_cattle_herd_kill_end"),
        (change_screen_loot, "trp_temp_troop"),
        (play_sound, "snd_cow_slaughter"),
    ], "."),

    ("cattle_kill_4", 
    [
        (ge, reg5, 4),
    ],
    "Four.",
    [
        (call_script, "script_kill_cattle_from_herd", "$g_encountered_party", 4),
        (jump_to_menu, "mnu_cattle_herd_kill_end"),
        (change_screen_loot, "trp_temp_troop"),
        (play_sound, "snd_cow_slaughter"),
    ], "."),

    ("cattle_kill_5", 
    [
        (ge, reg5, 5),
    ],
    "Five.",
    [
        (call_script, "script_kill_cattle_from_herd", "$g_encountered_party", 5),
        (jump_to_menu, "mnu_cattle_herd_kill_end"),
        (change_screen_loot, "trp_temp_troop"),
        (play_sound, "snd_cow_slaughter"),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_cattle_herd"),
    ], "."),

]),

("cattle_herd_kill_end", 0,
"{!}You shouldn't be reading this.",
"none", 
[
    (change_screen_return),
],
[
]),

("arena_duel_fight", 0,
"You and your opponent prepare to fight for honor.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$g_leave_encounter", 0),
        (try_begin),
            (is_between, "$g_encountered_party", "p_town_1", "p_castle_1"),
            (party_get_slot, ":var_0", "$g_encountered_party", slot_town_arena),
        (else_try),
            (eq, "$g_start_arena_fight_at_nearest_town", 1),
            (assign, ":var_1", -1),
            (assign, ":var_2", 10000),
            (try_for_range, ":var_3", "p_town_1", "p_castle_1"),
                (store_distance_to_party_from_party, ":var_4", ":var_3", "$g_encountered_party"),
                (neg|ge, ":var_4", ":var_2"),
                (assign, ":var_2", ":var_4"),
                (assign, ":var_1", ":var_3"),
            (try_end),
            (try_begin),
                (ge, ":var_1", 0),
                (party_get_slot, ":var_0", ":var_1", slot_town_arena),
            (try_end),
            (assign, "$g_start_arena_fight_at_nearest_town", 0),
        (else_try),
            (party_get_current_terrain, ":var_5", "p_main_party"),
            (eq, ":var_5", 4),
            (assign, ":var_0", "scn_training_ground_ranged_melee_3"),
        (else_try),
            (eq, ":var_5", 5),
            (assign, ":var_0", "scn_training_ground_ranged_melee_4"),
        (else_try),
            (assign, ":var_0", "scn_training_ground_ranged_melee_1"),
        (try_end),
        (modify_visitors_at_site, ":var_0"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 1, "$g_duel_troop"),
        (set_jump_mission, "mt_duel_with_lord"),
        (jump_to_scene, ":var_0"),
        (jump_to_menu, "mnu_arena_duel_conclusion"),
        (change_screen_mission),
    ], "."),

]),

("arena_duel_conclusion", 0,
"{!}{s11}",
"none", 
[
    (try_begin),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (try_end),
    (str_store_troop_name, s10, "$g_duel_troop"),
    (try_begin),
        (quest_slot_eq, "qst_duel_for_lady", 2, "$g_duel_troop"),
        (check_quest_failed, "qst_duel_for_lady"),
        (str_store_string, s11, "str_you_lie_stunned_for_several_minutes_then_stagger_to_your_feet_to_find_your_s10_standing_over_you_you_have_lost_the_duel"),
    (else_try),
        (quest_slot_eq, "qst_duel_for_lady", 2, "$g_duel_troop"),
        (check_quest_succeeded, "qst_duel_for_lady"),
        (str_store_string, s11, "str_s10_lies_in_the_arenas_dust_for_several_minutes_then_staggers_to_his_feet_you_have_won_the_duel"),
    (else_try),
        (quest_slot_eq, "qst_duel_courtship_rival", 2, "$g_duel_troop"),
        (check_quest_failed, "qst_duel_courtship_rival"),
        (str_store_string, s11, "str_you_lie_stunned_for_several_minutes_then_stagger_to_your_feet_to_find_your_s10_standing_over_you_you_have_lost_the_duel"),
    (else_try),
        (quest_slot_eq, "qst_duel_courtship_rival", 2, "$g_duel_troop"),
        (check_quest_succeeded, "qst_duel_courtship_rival"),
        (str_store_string, s11, "str_s10_lies_in_the_arenas_dust_for_several_minutes_then_staggers_to_his_feet_you_have_won_the_duel"),
    (else_try),
        (quest_slot_eq, "qst_duel_avenge_insult", 2, "$g_duel_troop"),
        (check_quest_succeeded, "qst_duel_avenge_insult"),
        (str_store_string, s11, "str_s10_lies_in_the_arenas_dust_for_several_minutes_then_staggers_to_his_feet_you_have_won_the_duel"),
    (else_try),
        (quest_slot_eq, "qst_duel_avenge_insult", 2, "$g_duel_troop"),
        (check_quest_failed, "qst_duel_avenge_insult"),
        (str_store_string, s11, "str_you_lie_stunned_for_several_minutes_then_stagger_to_your_feet_to_find_your_s10_standing_over_you_you_have_lost_the_duel"),
    (else_try),
        (quest_slot_eq, "qst_denounce_lord", 2, "$g_duel_troop"),
        (check_quest_succeeded, "qst_denounce_lord"),
        (str_store_string, s11, "str_s10_lies_in_the_arenas_dust_for_several_minutes_then_staggers_to_his_feet_you_have_won_the_duel"),
    (else_try),
        (quest_slot_eq, "qst_denounce_lord", 2, "$g_duel_troop"),
        (check_quest_failed, "qst_denounce_lord"),
        (str_store_string, s11, "str_you_lie_stunned_for_several_minutes_then_stagger_to_your_feet_to_find_your_s10_standing_over_you_you_have_lost_the_duel"),
    (else_try),
        (str_store_troop_name, s10, "$g_duel_troop"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (call_script, "script_get_meeting_scene"),
        (assign, ":var_0", reg0),
        (modify_visitors_at_site, ":var_0"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 17, "$g_duel_troop"),
        (set_jump_mission, "mt_conversation_encounter"),
        (jump_to_scene, ":var_0"),
        (assign, "$talk_context", 17),
        (change_screen_map_conversation, "$g_duel_troop"),
    ], "."),

]),

("simple_encounter", 4352,
"{s2} You have {reg10} troops fit for battle against their {reg11}.",
"none", 
[
    (assign, "$g_enemy_party", "$g_encountered_party"),
    (assign, "$g_ally_party", -1),
    (call_script, "script_encounter_calculate_fit"),
    (try_begin),
        (eq, "$new_encounter", 1),
        (assign, "$new_encounter", 0),
        (assign, "$g_encounter_is_in_village", 0),
        (assign, "$g_encounter_type", 0),
        (try_begin),
            (party_slot_eq, "$g_enemy_party", slot_party_ai_state, 5),
            (party_get_slot, ":var_0", "$g_enemy_party", slot_party_ai_object),
            (store_distance_to_party_from_party, ":var_1", ":var_0", "$g_enemy_party"),
            (try_begin),
                (neg|ge, ":var_1", 4),
                (assign, "$g_encounter_is_in_village", ":var_0"),
                (assign, "$g_encounter_type", 1),
            (try_end),
        (try_end),
        (try_begin),
            (gt, "$g_player_raiding_village", 0),
            (assign, "$g_encounter_is_in_village", "$g_player_raiding_village"),
            (assign, "$g_encounter_type", 2),
            (party_quick_attach_to_current_battle, "$g_encounter_is_in_village", 1),
            (str_store_string, s7, "@Villagers"),
            (display_message, "str_s1_joined_battle_enemy", 0xFF5050),
        (else_try),
            (eq, "$g_encounter_type", 1),
            (party_quick_attach_to_current_battle, "$g_encounter_is_in_village", 0),
            (str_store_string, s7, "@Villagers"),
            (display_message, "str_s1_joined_battle_friend", 0x50FF50),
        (try_end),
        (call_script, "script_let_nearby_parties_join_current_battle", 0, 0),
        (call_script, "script_encounter_init_variables"),
        (assign, "$encountered_party_hostile", 0),
        (assign, "$encountered_party_friendly", 0),
        (try_begin),
            (gt, "$g_encountered_party_relation", 0),
            (assign, "$encountered_party_friendly", 1),
        (try_end),
        (try_begin),
            (neg|ge, "$g_encountered_party_relation", 0),
            (assign, "$encountered_party_hostile", 1),
            (try_begin),
                (encountered_party_is_attacker),
                (assign, "$cant_leave_encounter", 1),
            (try_end),
        (try_end),
        (assign, "$talk_context", 2),
        (call_script, "script_setup_party_meeting", "$g_encountered_party"),
    (else_try),
        (try_begin),
            (eq, "$cant_leave_encounter", 1),
            (call_script, "script_party_count_members_with_full_health", "p_main_party_backup"),
            (assign, ":var_2", reg0),
            (call_script, "script_party_count_members_with_full_health", "p_encountered_party_backup"),
            (val_add, ":var_2", reg0),
            (call_script, "script_party_count_members_with_full_health", "p_main_party"),
            (assign, ":var_3", reg0),
            (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
            (val_add, ":var_3", reg0),
            (store_sub, ":var_4", ":var_2", 10),
            (neg|ge, ":var_3", ":var_4"),
            (assign, "$cant_leave_encounter", 0),
        (try_end),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (try_end),
    (try_begin),
        (party_is_active, "$g_encountered_party"),
        (str_store_party_name, s1, "$g_encountered_party"),
        (try_begin),
            (eq, "$g_encounter_type", 0),
            (str_store_string, s2, "@You have encountered {s1}."),
        (else_try),
            (eq, "$g_encounter_type", 1),
            (str_store_party_name, s3, "$g_encounter_is_in_village"),
            (str_store_string, s2, "@You have engaged {s1} while they were raiding {s3}."),
        (else_try),
            (eq, "$g_encounter_type", 2),
            (str_store_party_name, s3, "$g_encounter_is_in_village"),
            (str_store_string, s2, "@You were caught by {s1} while your forces were raiding {s3}."),
        (try_end),
    (try_end),
    (try_begin),
        (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
        (assign, ":var_5", reg0),
        (assign, ":var_6", 0),
        (try_begin),
            (eq, "$g_battle_result", 1),
            (this_or_next|neg|gt, ":var_5", 0),
            (neg|gt, ":var_5", "$num_routed_enemies"),
            (assign, ":var_6", 1),
        (else_try),
            (eq, "$g_engaged_enemy", 1),
            (this_or_next|neg|gt, ":var_5", 0),
            (neg|gt, "$g_enemy_fit_for_battle", "$num_routed_enemies"),
            (ge, "$g_friend_fit_for_battle", 1),
            (assign, ":var_6", 1),
        (try_end),
        (this_or_next|eq, ":var_6", 1),
        (eq, "$g_enemy_surrenders", 1),
        (assign, "$g_next_menu", -1),
        (jump_to_menu, "mnu_total_victory"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (assign, ":var_7", reg0),
        (assign, ":var_8", 0),
        (try_begin),
            (eq, "$g_battle_result", -1),
            (neg|gt, ":var_7", "$num_routed_us"),
            (assign, ":var_8", 1),
        (else_try),
            (eq, "$g_engaged_enemy", 1),
            (ge, "$g_enemy_fit_for_battle", 1),
            (neg|gt, "$g_friend_fit_for_battle", 0),
            (assign, ":var_8", 1),
        (try_end),
        (this_or_next|eq, ":var_8", 1),
        (eq, "$g_player_surrenders", 1),
        (assign, "$g_next_menu", "mnu_captivity_start_wilderness"),
        (jump_to_menu, "mnu_total_defeat"),
    (try_end),
    (try_begin),
        (eq, "$g_encountered_party_template", "pt_looters"),
        (set_background_mesh, "mesh_pic_bandits"),
    (else_try),
        (eq, "$g_encountered_party_template", "pt_mountain_bandits"),
        (set_background_mesh, "mesh_pic_mountain_bandits"),
    (else_try),
        (eq, "$g_encountered_party_template", "pt_steppe_bandits"),
        (set_background_mesh, "mesh_pic_steppe_bandits"),
    (else_try),
        (eq, "$g_encountered_party_template", "pt_sea_raiders"),
        (set_background_mesh, "mesh_pic_sea_raiders"),
    (else_try),
        (eq, "$g_encountered_party_template", "pt_forest_bandits"),
        (set_background_mesh, "mesh_pic_forest_bandits"),
    (else_try),
        (eq, "$g_encountered_party_template", "pt_deserters"),
        (set_background_mesh, "mesh_pic_deserters"),
    (else_try),
        (eq, "$g_encountered_party_template", "pt_kingdom_hero_party"),
        (party_stack_get_troop_id, ":var_9", "$g_encountered_party", 0),
        (ge, ":var_9", 1),
        (troop_get_slot, ":var_10", ":var_9", slot_troop_original_faction),
        (try_begin),
            (eq, ":var_10", 15),
            (set_background_mesh, "mesh_pic_swad"),
        (else_try),
            (eq, ":var_10", 16),
            (set_background_mesh, "mesh_pic_vaegir"),
        (else_try),
            (eq, ":var_10", 17),
            (set_background_mesh, "mesh_pic_khergit"),
        (else_try),
            (eq, ":var_10", 18),
            (set_background_mesh, "mesh_pic_nord"),
        (else_try),
            (eq, ":var_10", 19),
            (set_background_mesh, "mesh_pic_rhodock"),
        (try_end),
    (try_end),
],
[
    ("game_options_reinforce", [],
    "Change battle reinforce times",
    [
        (assign, "$temp", 101),
        (start_presentation, "prsnt_numeric_input"),
    ], "."),

    ("change_commander", 
    [
        (str_store_troop_name, s7, "$g_player_troop"),
        (set_player_troop, "$g_player_troop"),
    ],
    "Change commander.(Current commander: {s7})",
    [
        (start_presentation, "prsnt_change_commander"),
    ], "."),

    ("encounter_attack", 
    [
        (neg|troop_is_wounded, "$g_player_troop"),
    ],
    "Charge the enemy.",
    [
        (assign, "$g_battle_result", 0),
        (assign, "$g_engaged_enemy", 1),
        (party_get_template_id, ":var_0", "$g_encountered_party"),
        (try_begin),
            (eq, ":var_0", "pt_village_farmers"),
            (unlock_achievement, 27),
        (try_end),
        (try_begin),
            (check_quest_active, "qst_order_bounty"),
            (call_script, "script_party_calculate_strength", "$g_encountered_party", 0),
            (party_set_slot, "$g_encountered_party", slot_party_cached_strength, reg0),
            (party_get_num_attached_parties, ":var_1", "$g_encountered_party"),
            (try_for_range, ":var_2", 0, ":var_1"),
                (party_get_attached_party_with_rank, ":var_3", "$g_encountered_party", ":var_2"),
                (call_script, "script_party_calculate_strength", ":var_3", 0),
                (party_set_slot, ":var_3", slot_party_cached_strength, reg0),
            (try_end),
        (try_end),
        (call_script, "script_calculate_renown_value"),
        (call_script, "script_calculate_battle_advantage"),
        (set_battle_advantage, reg0),
        (set_party_battle_mode),
        (try_begin),
            (neg|eq, "$music_track_enemy", 0),
            (try_begin),
                (eq, "$music_track_enemy_playing", 1),
                (assign, "$music_track_enemy_playing", 0),
            (else_try),
                (music_set_situation, 1024),
                (play_track, "$music_track_enemy", 1),
            (try_end),
        (try_end),
        (try_begin),
            (eq, "$g_encounter_type", 1),
            (assign, "$g_village_raid_evil", 0),
            (set_jump_mission, "mt_village_raid"),
            (party_get_slot, ":var_4", "$g_encounter_is_in_village", slot_town_center),
            (jump_to_scene, ":var_4"),
        (else_try),
            (eq, "$g_encounter_type", 2),
            (assign, "$g_village_raid_evil", 0),
            (set_jump_mission, "mt_village_raid"),
            (party_get_slot, ":var_4", "$g_encounter_is_in_village", slot_town_center),
            (jump_to_scene, ":var_4"),
        (else_try),
            (set_jump_mission, "mt_lead_charge"),
            (call_script, "script_setup_random_scene"),
        (try_end),
        (assign, "$g_next_menu", "mnu_simple_encounter"),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

    ("encounter_order_attack", 
    [
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (ge, reg0, 4),
    ],
    "Order your troops to attack without you.",
    [
        (jump_to_menu, "mnu_order_attack_begin"),
    ], "."),

    ("encounter_leave", 
    [
        (eq, "$cant_leave_encounter", 0),
    ],
    "Leave.",
    [
        (try_begin),
            (eq, "$encountered_party_friendly", 0),
            (encountered_party_is_attacker),
            (call_script, "script_objectionable_action", 1, "str_flee_battle"),
        (try_end),
        (try_begin),
            (eq, "$encountered_party_friendly", 0),
            (party_get_num_companion_stacks, ":var_0", "p_encountered_party_backup"),
            (try_for_range, ":var_1", 0, ":var_0"),
                (party_stack_get_troop_id, ":var_2", "p_encountered_party_backup", ":var_1"),
                (is_between, ":var_2", "trp_npc_adonja", "trp_knight_1_1_wife"),
                (troop_slot_eq, ":var_2", slot_troop_occupation, 2),
                (store_troop_faction, ":var_3", ":var_2"),
                (call_script, "script_add_log_entry", 15, "trp_player", -1, ":var_2", ":var_3"),
            (try_end),
        (try_end),
        (leave_encounter),
        (change_screen_return),
    ], "."),

    ("encounter_retreat", 
    [
        (eq, "$cant_leave_encounter", 1),
        (call_script, "script_get_max_skill_of_player_party", "skl_tactics"),
        (assign, ":var_0", reg0),
        (val_add, ":var_0", 4),
        (call_script, "script_party_count_members_with_full_health", "p_collective_enemy", 0),
        (assign, ":var_1", reg0),
        (val_div, ":var_1", 2),
        (val_div, ":var_1", ":var_0"),
        (val_max, ":var_1", 1),
        (call_script, "script_party_count_fit_regulars", "p_main_party"),
        (assign, ":var_2", reg0),
        (ge, ":var_2", ":var_1"),
    ],
    "Pull back, leaving some soldiers behind to cover your retreat.",
    [
        (jump_to_menu, "mnu_encounter_retreat_confirm"),
    ], "."),

    ("encounter_surrender", 
    [
        (eq, "$cant_leave_encounter", 1),
    ],
    "Surrender.",
    [
        (assign, "$g_player_surrenders", 1),
    ], "."),

]),

("encounter_retreat_confirm", 0,
"As the party member with the highest tactics skill, ({reg2}), {reg3?you devise:{s3} devises} a plan that will allow you and your men to escape with your lives, but you'll have to leave {reg4} soldiers behind to stop the enemy from giving chase.",
"none", 
[
    (call_script, "script_get_max_skill_of_player_party", "skl_tactics"),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (assign, reg2, ":var_0"),
    (val_add, ":var_0", 4),
    (call_script, "script_party_count_members_with_full_health", "p_collective_enemy", 0),
    (assign, ":var_2", reg0),
    (val_div, ":var_2", 2),
    (store_div, reg4, ":var_2", ":var_0"),
    (val_max, reg4, 1),
    (try_begin),
        (eq, ":var_1", "trp_player"),
        (assign, reg3, 1),
    (else_try),
        (assign, reg3, 0),
        (str_store_troop_name, s3, ":var_1"),
    (try_end),
],
[
    ("leave_behind", [],
    "Go on. The sacrifice of these men will save the rest.",
    [
        (assign, ":var_0", reg4),
        (try_for_range, ":var_1", 0, ":var_0"),
            (call_script, "script_cf_party_remove_random_regular_troop", "p_main_party"),
            (assign, ":var_2", reg0),
            (store_random_in_range, ":var_3", 0, 100),
            (ge, ":var_3", 30),
            (party_add_prisoners, "$g_encountered_party", ":var_2", 1),
        (try_end),
        (call_script, "script_change_player_party_morale", -20),
        (jump_to_menu, "mnu_encounter_retreat"),
    ], "."),

    ("dont_leave_behind", [],
    "No. We leave no one behind.",
    [
        (jump_to_menu, "mnu_simple_encounter"),
    ], "."),

]),

("encounter_retreat", 0,
"You tell {reg4} of your troops to hold the enemy while you retreat with the rest of your party.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (call_script, "script_objectionable_action", 1, "str_flee_battle"),
        (party_get_num_companion_stacks, ":var_0", "p_encountered_party_backup"),
        (try_for_range, ":var_1", 0, ":var_0"),
            (party_stack_get_troop_id, ":var_2", "p_encountered_party_backup", ":var_1"),
            (is_between, ":var_2", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (troop_slot_eq, ":var_2", slot_troop_occupation, 2),
            (store_troop_faction, ":var_3", ":var_2"),
            (call_script, "script_add_log_entry", 16, "trp_player", -1, ":var_2", ":var_3"),
        (try_end),
        (party_ignore_player, "$g_encountered_party", 1),
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("order_attack_begin", 0,
"Your troops prepare to attack the enemy.",
"none", [],
[
    ("order_attack_begin", [],
    "Order the attack to begin.",
    [
        (party_get_template_id, ":var_0", "$g_encountered_party"),
        (try_begin),
            (eq, ":var_0", "pt_village_farmers"),
            (unlock_achievement, 27),
        (try_end),
        (assign, "$g_engaged_enemy", 1),
        (jump_to_menu, "mnu_order_attack_2"),
    ], "."),

    ("call_back", [],
    "Call them back.",
    [
        (jump_to_menu, "mnu_simple_encounter"),
    ], "."),

]),

("order_attack_2", 512,
"{s4}^^Your casualties: {s8}^^Enemy casualties: {s9}^^Allies remaining: {reg10}^Enemies remaining: {reg11}",
"none", 
[
    (set_background_mesh, "mesh_pic_charge"),
    (call_script, "script_kt_party_calculate_strength_with_attachments", "p_main_party", 1, 0),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (call_script, "script_kt_party_calculate_strength", "p_collective_enemy", 0, 0),
    (assign, ":var_2", reg0),
    (assign, ":var_3", reg1),
    (try_begin),
        (store_faction_of_party, ":var_4", "$g_encountered_party"),
        (eq, ":var_4", "fac_noldor_elves"),
        (val_mul, ":var_2", 2),
        (val_mul, ":var_3", 2),
    (try_end),
    (val_mul, ":var_0", ":var_3"),
    (val_mul, ":var_2", ":var_1"),
    (val_div, ":var_0", 100),
    (val_div, ":var_2", 100),
    (val_max, ":var_0", 1),
    (val_max, ":var_2", 1),
    (val_div, ":var_0", 50),
    (val_div, ":var_2", 50),
    (inflict_casualties_to_party_group, "p_main_party", ":var_2", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s8, 0),
    (inflict_casualties_to_party_group, "$g_encountered_party", ":var_0", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s9, 0),
    (party_get_num_companion_stacks, ":var_5", "p_temp_casualties"),
    (try_for_range, ":var_6", 0, ":var_5"),
        (party_stack_get_troop_id, ":var_7", "p_temp_casualties", ":var_6"),
        (try_begin),
            (party_stack_get_size, ":var_8", "p_temp_casualties", ":var_6"),
            (gt, ":var_8", 0),
            (party_add_members, "p_total_enemy_casualties", ":var_7", ":var_8"),
            (party_stack_get_num_wounded, ":var_9", "p_temp_casualties", ":var_6"),
            (gt, ":var_9", 0),
            (party_wound_members, "p_total_enemy_casualties", ":var_7", ":var_9"),
        (try_end),
    (try_end),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s9, 0),
    (party_collect_attachments_to_party, "$g_encountered_party", "p_collective_enemy"),
    (assign, "$no_soldiers_left", 0),
    (try_begin),
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (assign, ":var_10", reg0),
        (store_add, ":var_11", "$num_routed_us", 1),
        (neg|gt, ":var_10", ":var_11"),
        (assign, "$no_soldiers_left", 1),
        (str_store_string, s4, "str_order_attack_failure"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
        (assign, ":var_12", reg0),
        (this_or_next|neg|gt, ":var_12", 0),
        (neg|gt, ":var_12", "$num_routed_enemies"),
        (assign, ":var_13", 0),
        (party_get_num_companion_stacks, ":var_14", "p_collective_enemy"),
        (try_begin),
            (eq, ":var_14", 0),
            (assign, ":var_13", 1),
        (else_try),
            (party_stack_get_troop_id, ":var_15", "p_collective_enemy", 0),
            (try_begin),
                (neg|troop_is_hero, ":var_15"),
                (assign, ":var_13", 1),
            (else_try),
                (troop_is_wounded, ":var_15"),
                (assign, ":var_13", 1),
            (try_end),
        (try_end),
        (eq, ":var_13", 1),
        (assign, "$g_battle_result", 1),
        (assign, "$no_soldiers_left", 1),
        (str_store_string, s4, "str_order_attack_success"),
    (else_try),
        (str_store_string, s4, "str_order_attack_continue"),
    (try_end),
    (call_script, "script_encounter_calculate_fit"),
],
[
    ("order_attack_continue", 
    [
        (eq, "$no_soldiers_left", 0),
    ],
    "Order your soldiers to continue the attack.",
    [
        (jump_to_menu, "mnu_order_attack_2"),
    ], "."),

    ("order_retreat", 
    [
        (eq, "$no_soldiers_left", 0),
    ],
    "Call your soldiers back.",
    [
        (jump_to_menu, "mnu_simple_encounter"),
    ], "."),

    ("continue", 
    [
        (eq, "$no_soldiers_left", 1),
    ],
    "Continue...",
    [
        (jump_to_menu, "mnu_simple_encounter"),
    ], "."),

]),

("battle_debrief", 4608,
"{s11}^^Your Casualties:{s8}{s10}^^Enemy Casualties:{s9}^^Kill Stat:{s30}",
"none", 
[
    (str_clear, s30),
    (party_get_num_companion_stacks, ":var_120", "p_main_party"),
    (try_for_range, ":var_121", 0, ":var_120"),
        (party_stack_get_troop_id, ":var_125", "p_main_party", ":var_121"),
        (str_store_troop_name, s29, ":var_125"),
        (troop_get_slot, reg21, ":var_125", 254),
        (try_begin),
            (troop_is_hero, ":var_125"),
            (troop_get_slot, reg22, ":var_125", 255),
            (str_store_string, s30, "@{s30}^{s29}'s kill count: {reg21} (total: {reg22})"),
        (else_try),
            (str_store_string, s30, "@{s30}^{s29}'s kill count: {reg21}"),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$g_battle_result", 1),
        (call_script, "script_change_troop_renown", "trp_player", "$battle_renown_value"),
        (try_begin),
            (check_quest_active, "qst_order_challenge"),
            (neg|check_quest_succeeded, "qst_order_challenge"),
            (neg|check_quest_failed, "qst_order_challenge"),
            (quest_get_slot, ":var_120", "qst_order_challenge", 17),
            (val_add, ":var_120", "$battle_renown_value"),
            (quest_set_slot, "qst_order_challenge", 17, ":var_120"),
            (assign, reg1, ":var_120"),
            (quest_get_slot, reg2, "qst_order_challenge", 10),
            (display_message, "@Challenge quest renown earned so far: {reg1}/{reg2}."),
            (str_store_string, s3, "@Renown earned so far: {reg1}."),
            (add_quest_note_from_sreg, "qst_order_challenge", 3, 3, 0),
            (try_begin),
                (ge, reg1, reg2),
                (call_script, "script_succeed_quest", "qst_order_challenge"),
            (try_end),
        (try_end),
        (try_begin),
            (ge, "$g_encountered_party", 0),
            (party_is_active, "$g_encountered_party"),
            (party_get_template_id, ":var_121", "$g_encountered_party"),
            (eq, ":var_121", "pt_kingdom_caravan_party"),
            (get_achievement_stat, ":var_125", 30, 0),
            (get_achievement_stat, ":var_11", 30, 1),
            (val_add, ":var_11", 1),
            (set_achievement_stat, 30, 1, ":var_11"),
            (try_begin),
                (ge, ":var_125", 3),
                (ge, ":var_11", 3),
                (unlock_achievement, 30),
            (try_end),
        (try_end),
        (try_begin),
            (party_get_current_terrain, ":var_21", "p_main_party"),
            (eq, ":var_21", 4),
            (get_achievement_stat, ":var_22", 8, 0),
            (val_add, ":var_22", 1),
            (set_achievement_stat, 8, 0, ":var_22"),
            (try_begin),
                (eq, ":var_22", 10),
                (unlock_achievement, 8),
            (try_end),
        (try_end),
        (try_begin),
            (ge, "$g_enemy_party", 0),
            (party_is_active, "$g_enemy_party"),
            (party_stack_get_troop_id, ":var_20", "$g_enemy_party", 0),
            (eq, ":var_20", "trp_mountain_bandit"),
            (get_achievement_stat, ":var_10", 13, 0),
            (val_add, ":var_10", 1),
            (set_achievement_stat, 13, 0, ":var_10"),
            (try_begin),
                (eq, ":var_10", 10),
                (unlock_achievement, 13),
            (try_end),
        (try_end),
        (try_begin),
            (is_between, "$g_ally_party", "p_town_1", "p_village_1"),
            (unlock_achievement, 1),
        (try_end),
        (try_begin),
            (eq, "$g_joined_battle_to_help", 1),
            (unlock_achievement, 34),
        (try_end),
    (try_end),
    (assign, "$g_joined_battle_to_help", 0),
    (assign, "$g_player_troop", "trp_player"),
    (set_player_troop, "trp_player"),
    (call_script, "script_count_casualties_and_adjust_morale"),
    (call_script, "script_encounter_calculate_fit"),
    (call_script, "script_party_count_fit_regulars", "p_main_party"),
    (assign, "$playerparty_postbattle_regulars", reg0),
    (try_begin),
        (eq, "$g_battle_result", 1),
        (eq, "$g_enemy_fit_for_battle", 0),
        (str_store_string, s11, "@You were victorious!"),
        (call_script, "script_music_set_situation_with_culture", 8388608),
        (try_begin),
            (gt, "$g_friend_fit_for_battle", 1),
            (set_background_mesh, "mesh_pic_victory"),
        (try_end),
    (else_try),
        (eq, "$g_battle_result", -1),
        (ge, "$g_enemy_fit_for_battle", 1),
        (this_or_next|neg|gt, "$g_friend_fit_for_battle", 0),
        (neg|gt, "$playerparty_postbattle_regulars", 0),
        (str_store_string, s11, "@The battle was lost. Your forces were utterly crushed."),
        (set_background_mesh, "mesh_pic_defeat"),
    (else_try),
        (eq, "$g_battle_result", -1),
        (str_store_string, s11, "@Your companions carry you away from the fighting."),
        (troop_get_type, ":var_8", "$g_player_troop"),
        (try_begin),
            (ge, ":var_8", 1),
            (set_background_mesh, "mesh_pic_wounded_fem"),
        (else_try),
            (set_background_mesh, "mesh_pic_wounded"),
        (try_end),
    (else_try),
        (eq, "$g_battle_result", 1),
        (str_store_string, s11, "@You have defeated the enemy."),
        (try_begin),
            (gt, "$g_friend_fit_for_battle", 1),
            (set_background_mesh, "mesh_pic_victory"),
        (try_end),
    (else_try),
        (eq, "$g_battle_result", 0),
        (str_store_string, s11, "@You have retreated from the fight."),
    (try_end),
    (try_begin),
        (gt, "$playerparty_prebattle_regulars", 9),
        (store_add, ":var_9", 3, "$g_battle_result"),
        (store_div, ":var_10", "$playerparty_prebattle_regulars", ":var_9"),
        (neg|ge, "$playerparty_postbattle_regulars", ":var_10"),
        (call_script, "script_objectionable_action", 2, "str_excessive_casualties"),
    (try_end),
    (call_script, "script_print_casualties_to_s0", "p_player_casualties", 0),
    (str_store_string_reg, s8, 0),
    (call_script, "script_print_casualties_to_s0", "p_enemy_casualties", 0),
    (str_store_string_reg, s9, 0),
    (str_clear, s10),
    (try_begin),
        (eq, "$any_allies_at_the_last_battle", 1),
        (call_script, "script_print_casualties_to_s0", "p_ally_casualties", 0),
        (str_store_string, s10, "@^^Ally Casualties:{s0}"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "$g_next_menu"),
    ], "."),

]),

("total_victory", 0,
"You shouldn't be reading this... {s9}",
"none", 
[
    (assign, ":var_0", 0),
    (try_begin),
        (eq, "$routed_party_added", 0),
        (assign, "$routed_party_added", 1),
        (call_script, "script_add_routed_party"),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_track_down_bandits"),
        (neg|check_quest_succeeded, "qst_track_down_bandits"),
        (neg|check_quest_failed, "qst_track_down_bandits"),
        (quest_get_slot, ":var_1", "qst_track_down_bandits", 8),
        (party_is_active, ":var_1"),
        (party_get_attached_to, ":var_2"),
        (this_or_next|eq, ":var_1", "$g_enemy_party"),
        (eq, ":var_2", "$g_enemy_party"),
        (call_script, "script_succeed_quest", "qst_track_down_bandits"),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_rescue_daughter"),
        (neg|check_quest_succeeded, "qst_rescue_daughter"),
        (quest_get_slot, ":var_3", "qst_rescue_daughter", 2),
        (troop_slot_eq, ":var_3", slot_troop_leaded_party, "$g_encountered_party"),
        (party_force_add_members, "p_main_party", "trp_kidnapped_daughter", 1),
        (call_script, "script_succeed_quest", "qst_rescue_daughter"),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_order_bounty"),
        (neg|check_quest_succeeded, "qst_order_bounty"),
        (neg|check_quest_failed, "qst_order_bounty"),
        (quest_get_slot, ":var_4", "qst_order_bounty", 17),
        (quest_get_slot, ":var_5", "qst_order_bounty", 6),
        (store_troop_faction, ":var_6", ":var_5"),
        (party_get_slot, ":var_7", "$g_enemy_party", slot_party_cached_strength),
        (try_begin),
            (store_faction_of_party, ":var_8", "$g_enemy_party"),
            (party_get_template_id, ":var_9", "$g_enemy_party"),
            (this_or_next|faction_slot_eq, ":var_6", 100, ":var_8"),
            (this_or_next|faction_slot_eq, ":var_6", 101, ":var_8"),
            (this_or_next|faction_slot_eq, ":var_6", 102, ":var_9"),
            (faction_slot_eq, ":var_6", 103, ":var_9"),
            (val_add, ":var_4", ":var_7"),
        (try_end),
        (party_set_slot, "$g_enemy_party", slot_party_cached_strength, 0),
        (party_get_num_attached_parties, ":var_10", "$g_enemy_party"),
        (try_for_range, ":var_11", 0, ":var_10"),
            (party_get_attached_party_with_rank, ":var_12", "$g_enemy_party", ":var_11"),
            (party_get_slot, ":var_7", ":var_12", slot_party_cached_strength),
            (try_begin),
                (store_faction_of_party, ":var_8", "$g_enemy_party"),
                (party_get_template_id, ":var_9", "$g_enemy_party"),
                (this_or_next|faction_slot_eq, ":var_6", 100, ":var_8"),
                (this_or_next|faction_slot_eq, ":var_6", 101, ":var_8"),
                (this_or_next|faction_slot_eq, ":var_6", 102, ":var_9"),
                (faction_slot_eq, ":var_6", 103, ":var_9"),
                (val_add, ":var_4", ":var_7"),
            (try_end),
            (party_set_slot, ":var_12", slot_party_cached_strength, 0),
        (try_end),
        (quest_set_slot, "qst_order_bounty", 17, ":var_4"),
        (quest_get_slot, reg5, "qst_order_bounty", 10),
        (assign, reg4, ":var_4"),
        (str_store_string, s3, "@Current progress: {reg4}/{reg5}."),
        (add_quest_note_from_sreg, "qst_order_bounty", 3, 3, 0),
    (try_end),
    (try_begin),
        (gt, "$g_private_battle_with_troop", 0),
        (troop_slot_eq, "$g_private_battle_with_troop", slot_troop_leaded_party, "$g_encountered_party"),
        (assign, "$g_private_battle_with_troop", 0),
        (assign, "$g_disable_condescending_comments", 1),
    (try_end),
    (party_get_num_companion_stacks, ":var_13", "p_collective_enemy"),
    (try_for_range, ":var_14", 0, ":var_13"),
        (party_stack_get_troop_id, ":var_15", "p_collective_enemy", ":var_14"),
        (is_between, ":var_15", "trp_knight_1_1", "trp_kingdom_1_pretender"),
        (troop_is_wounded, ":var_15"),
        (party_add_members, "p_total_enemy_casualties", ":var_15", 1),
    (try_end),
    (try_begin),
        (eq, "$thanked_by_ally_leader", 0),
        (assign, "$thanked_by_ally_leader", 1),
        (gt, "$g_ally_party", 0),
        (store_add, ":var_16", "$g_starting_strength_friends", "$g_starting_strength_enemy_party"),
        (val_sub, ":var_16", "$g_starting_strength_main_party"),
        (store_sub, ":var_17", "$g_starting_strength_friends", "$g_starting_strength_main_party"),
        (store_mul, ":var_18", ":var_17", 100),
        (val_add, ":var_16", 1),
        (val_div, ":var_18", ":var_16"),
        (store_sub, ":var_19", 100, ":var_18"),
        (store_mul, ":var_20", ":var_19", "$g_starting_strength_enemy_party"),
        (val_div, ":var_20", 3000),
        (val_min, ":var_20", 4),
        (store_mul, "$g_relation_boost", ":var_19", ":var_19"),
        (val_div, "$g_relation_boost", 700),
        (val_clamp, "$g_relation_boost", 0, 20),
        (party_get_num_companion_stacks, ":var_21", "$g_ally_party"),
        (gt, ":var_21", 0),
        (store_faction_of_party, ":var_22", "$g_ally_party"),
        (call_script, "script_change_player_relation_with_faction", ":var_22", ":var_20"),
        (try_begin),
            (troop_slot_eq, "trp_player", 162, ":var_22"),
            (store_mul, ":var_23", ":var_22", 3),
            (val_div, ":var_23", 4),
            (call_script, "script_change_rank_points_with_order", ":var_22", ":var_23"),
        (try_end),
        (store_faction_of_party, ":var_8", "$g_enemy_party"),
        (val_mul, ":var_20", -1),
        (call_script, "script_change_player_relation_with_faction", ":var_8", ":var_20"),
        (party_stack_get_troop_id, ":var_24", "$g_ally_party"),
        (party_stack_get_troop_dna, ":var_25", "$g_ally_party", 0),
        (try_begin),
            (troop_is_hero, ":var_24"),
            (troop_get_slot, ":var_26", ":var_24", slot_troop_player_relation),
            (assign, ":var_27", "$g_relation_boost"),
            (try_begin),
                (neg|ge, ":var_26", -5),
                (val_div, ":var_27", 3),
            (try_end),
            (call_script, "script_change_player_relation_with_troop", ":var_24", ":var_27"),
        (try_end),
        (assign, "$talk_context", 13),
        (call_script, "script_setup_troop_meeting", ":var_24", ":var_25"),
    (else_try),
        (assign, ":var_0", 0),
        (party_get_num_companion_stacks, ":var_13", "p_total_enemy_casualties"),
        (try_for_range, ":var_28", "$last_defeated_hero", ":var_13"),
            (eq, ":var_0", 0),
            (party_stack_get_troop_id, ":var_15", "p_total_enemy_casualties", ":var_28"),
            (party_stack_get_troop_dna, ":var_29", "p_total_enemy_casualties", ":var_28"),
            (troop_is_hero, ":var_15"),
            (store_troop_faction, ":var_30", ":var_15"),
            (try_begin),
                (store_relation, ":var_31", ":var_30", "fac_player_faction"),
                (ge, ":var_31", 0),
                (str_store_troop_name, s4, ":var_15"),
                (try_begin),
                    (eq, "$cheat_mode", 1),
                    (display_message, "@{!}{s4} skipped in p total enemy casualties capture queue because is friendly"),
                (try_end),
            (else_try),
                (try_begin),
                    (party_stack_get_troop_id, ":var_32", "$g_encountered_party", 0),
                    (is_between, ":var_32", "trp_npc_adonja", "trp_knight_1_1_wife"),
                    (troop_slot_eq, ":var_32", slot_troop_occupation, 2),
                    (store_sub, ":var_33", ":var_32", "trp_npc_adonja"),
                    (get_achievement_stat, ":var_34", 7, ":var_33"),
                    (eq, ":var_34", 1),
                    (unlock_achievement, 7),
                (try_end),
                (store_add, "$last_defeated_hero", ":var_28", 1),
                (call_script, "script_remove_troop_from_prison", ":var_15"),
                (troop_set_slot, ":var_15", slot_troop_leaded_party, -1),
                (call_script, "script_cf_check_hero_can_escape_from_player", ":var_15"),
                (str_store_troop_name, s1, ":var_15"),
                (str_store_faction_name, s3, ":var_30"),
                (str_store_string, s17, "@{s1} of the {s3} managed to escape."),
                (display_log_message, "@{!}{s17}"),
                (jump_to_menu, "mnu_enemy_slipped_away"),
                (assign, ":var_0", 1),
            (else_try),
                (store_add, "$last_defeated_hero", ":var_28", 1),
                (call_script, "script_remove_troop_from_prison", ":var_15"),
                (troop_set_slot, ":var_15", slot_troop_leaded_party, -1),
                (assign, "$talk_context", 9),
                (call_script, "script_setup_troop_meeting", ":var_15", ":var_29"),
                (assign, ":var_0", 1),
            (try_end),
        (try_end),
        (eq, ":var_0", 1),
    (else_try),
        (assign, ":var_0", 0),
        (party_get_num_prisoner_stacks, ":var_35", "p_collective_enemy"),
        (try_for_range, ":var_28", "$last_freed_hero", ":var_35"),
            (eq, ":var_0", 0),
            (party_prisoner_stack_get_troop_id, ":var_15", "p_collective_enemy", ":var_28"),
            (troop_is_hero, ":var_15"),
            (neg|is_between, ":var_15", "trp_hero_burilgi", "trp_omen_seeker"),
            (party_prisoner_stack_get_troop_dna, ":var_29", "p_collective_enemy", ":var_28"),
            (store_add, "$last_freed_hero", ":var_28", 1),
            (assign, "$talk_context", 8),
            (call_script, "script_setup_troop_meeting", ":var_15", ":var_29"),
            (assign, ":var_0", 1),
        (try_end),
        (eq, ":var_0", 1),
    (else_try),
        (eq, "$capture_screen_shown", 0),
        (assign, "$capture_screen_shown", 1),
        (party_clear, "p_temp_party"),
        (assign, "$g_move_heroes", 0),
        (call_script, "script_party_add_wounded_members_as_prisoners", "p_temp_party", "p_total_enemy_casualties"),
        (call_script, "script_party_add_party_prisoners", "p_temp_party", "p_collective_enemy"),
        (try_begin),
            (call_script, "script_party_calculate_strength", "p_collective_friends_backup", 0),
            (assign, ":var_36", reg0),
            (gt, ":var_36", 0),
            (call_script, "script_party_calculate_strength", "p_main_party_backup", 0),
            (assign, ":var_37", reg0),
            (store_sub, ":var_38", ":var_36", ":var_37"),
            (store_mul, ":var_39", ":var_38", 1000),
            (val_div, ":var_39", ":var_36"),
            (assign, "$pin_number", ":var_39"),
            (party_clear, "p_temp_party_2"),
            (call_script, "script_move_members_with_ratio", "p_temp_party", "p_temp_party_2"),
            (try_begin),
                (gt, "$g_ally_party", 0),
                (distribute_party_among_party_group, "p_temp_party_2", "$g_ally_party"),
            (try_end),
        (try_end),
        (party_get_num_companions, ":var_40", "p_temp_party"),
        (party_get_num_prisoners, ":var_41", "p_temp_party"),
        (store_add, ":var_42", ":var_40", ":var_41"),
        (gt, ":var_42", 0),
        (neg|check_quest_active, "qst_order_challenge"),
        (change_screen_exchange_with_party, "p_temp_party"),
    (else_try),
        (eq, "$loot_screen_shown", 0),
        (assign, "$loot_screen_shown", 1),
        (try_begin),
            (gt, "$g_ally_party", 0),
            (call_script, "script_party_add_party", "$g_ally_party", "p_temp_party"),
        (else_try),
            (party_get_num_attached_parties, ":var_43", "p_main_party"),
            (gt, ":var_43", 0),
            (party_get_attached_party_with_rank, ":var_44", "p_main_party", 0),
            (call_script, "script_party_add_party", ":var_44", "p_temp_party"),
        (try_end),
        (troop_clear_inventory, "trp_temp_troop"),
        (call_script, "script_party_calculate_loot", "p_total_enemy_casualties"),
        (gt, reg0, 0),
        (troop_sort_inventory, "trp_temp_troop"),
        (try_begin),
            (call_script, "script_get_count_of_companions"),
            (assign, "$return_menu", "mnu_total_victory"),
            (assign, "$inventory_menu_offset", 0),
            (str_clear, s30),
            (jump_to_menu, "mnu_manage_loot_pool"),
        (else_try),
            (change_screen_loot, "trp_temp_troop"),
        (try_end),
    (else_try),
        (try_begin),
            (neg|gt, "$g_ally_party", 0),
            (end_current_battle),
        (try_end),
        (call_script, "script_party_give_xp_and_gold", "p_total_enemy_casualties"),
        (try_begin),
            (eq, "$g_enemy_party", 0),
            (display_message, "str_error_string"),
        (try_end),
        (try_begin),
            (party_is_active, "$g_ally_party"),
            (call_script, "script_battle_political_consequences", "$g_enemy_party", "$g_ally_party"),
        (else_try),
            (call_script, "script_battle_political_consequences", "$g_enemy_party", "p_main_party"),
        (try_end),
        (call_script, "script_event_player_defeated_enemy_party", "$g_enemy_party"),
        (call_script, "script_clear_party_group", "$g_enemy_party"),
        (try_begin),
            (eq, "$g_next_menu", -1),
            (call_script, "script_post_battle_personality_clash_check"),
            (party_stack_get_troop_id, ":var_45", "p_encountered_party_backup", 0),
            (try_begin),
                (is_between, ":var_45", "trp_npc_adonja", "trp_knight_1_1_wife"),
                (neg|is_between, "$g_encountered_party", "p_town_1", "p_salt_mine"),
                (store_troop_faction, ":var_46", ":var_45"),
                (try_begin),
                    (eq, "$g_ally_party", 0),
                    (call_script, "script_add_log_entry", 11, "trp_player", -1, ":var_45", ":var_46"),
                    (try_begin),
                        (eq, "$cheat_mode", 1),
                        (display_message, "@{!}Victory comment. Player was alone"),
                    (try_end),
                (else_try),
                    (ge, "$g_strength_contribution_of_player", 40),
                    (call_script, "script_add_log_entry", 11, "trp_player", -1, ":var_45", ":var_46"),
                    (try_begin),
                        (eq, "$cheat_mode", 1),
                        (display_message, "@{!}Ordinary victory comment. The player provided at least 40 percent forces."),
                    (try_end),
                (else_try),
                    (gt, "$g_starting_strength_enemy_party", 1000),
                    (call_script, "script_get_closest_center", "p_main_party"),
                    (assign, ":var_47", reg0),
                    (call_script, "script_add_log_entry", 19, "trp_player", ":var_47", -1, ":var_46"),
                    (try_begin),
                        (eq, "$cheat_mode", 1),
                        (display_message, "@{!}Player participation comment. The enemy had at least 1k starting strength."),
                    (try_end),
                (else_try),
                    (eq, "$cheat_mode", 1),
                    (display_message, "@{!}No victory comment. The battle was small, and the player provided less than 40 percent of allied strength"),
                (try_end),
            (try_end),
            (val_add, "$g_total_victories", 1),
            (try_begin),
                (neg|encountered_party_is_attacker),
                (neg|gt, "$g_ally_party", 0),
                (party_stack_get_troop_id, ":var_45", "p_encountered_party_backup", 0),
                (neg|is_between, ":var_45", "trp_npc_adonja", "trp_knight_1_1_wife"),
                (store_faction_of_party, ":var_8", "$g_enemy_party"),
                (call_script, "script_change_player_relation_with_faction", ":var_8", -4),
            (try_end),
            (leave_encounter),
            (change_screen_return),
        (else_try),
            (eq, "$g_next_menu", "mnu_noldor_castle_victory"),
            (jump_to_menu, "$g_next_menu"),
        (else_try),
            (eq, "$g_next_menu", "mnu_stronghold_victory"),
            (jump_to_menu, "$g_next_menu"),
        (else_try),
            (try_begin),
                (eq, "$g_next_menu", "mnu_castle_taken"),
                (call_script, "script_add_log_entry", 10, "trp_player", "$g_encountered_party", -1, "$g_encountered_party_faction"),
                (store_current_hours, ":var_48"),
                (faction_set_slot, "$players_kingdom", slot_faction_ai_last_decisive_event, ":var_48"),
                (try_begin),
                    (is_between, "$players_kingdom", "fac_kingdom_1", "fac_kingdoms_end"),
                    (jump_to_menu, "$g_next_menu"),
                (else_try),
                    (eq, "$players_kingdom", "fac_player_supporters_faction"),
                    (assign, "$g_center_taken_by_player_faction", "$g_encountered_party"),
                    (neg|faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
                    (faction_get_slot, ":var_49", "fac_player_supporters_faction", slot_faction_leader),
                    (change_screen_return),
                    (start_map_conversation, ":var_49", -1),
                (else_try),
                    (neg|is_between, "$players_kingdom", "fac_kingdom_1", "fac_kingdoms_end"),
                    (assign, "$g_center_taken_by_player_faction", "$g_encountered_party"),
                    (assign, "$talk_context", 20),
                    (change_screen_return),
                    (assign, ":var_50", "trp_sarleon_arm_longbowman"),
                    (assign, ":var_51", 0),
                    (party_get_num_companion_stacks, ":var_13", "p_main_party"),
                    (try_for_range, ":var_28", 0, ":var_13"),
                        (party_stack_get_troop_id, ":var_15", "p_main_party", ":var_28"),
                        (neg|eq, ":var_15", "trp_player"),
                        (party_stack_get_size, ":var_52", "p_main_party", ":var_28"),
                        (party_stack_get_num_wounded, ":var_53", "p_main_party", ":var_28"),
                        (troop_get_slot, ":var_54", "p_main_party", slot_troop_player_routed_agents),
                        (assign, ":var_55", 0),
                        (try_begin),
                            (neg|troop_is_hero, ":var_15"),
                            (store_add, ":var_56", ":var_53", ":var_54"),
                            (gt, ":var_52", ":var_56"),
                            (assign, ":var_55", 1),
                        (else_try),
                            (troop_is_hero, ":var_15"),
                            (neg|troop_is_wounded, ":var_15"),
                            (assign, ":var_55", 1),
                        (try_end),
                        (eq, ":var_55", 1),
                        (try_begin),
                            (troop_is_hero, ":var_15"),
                            (troop_get_slot, ":var_57", ":var_15", slot_troop_renown),
                            (store_mul, ":var_58", ":var_57", 100),
                            (val_add, ":var_58", 1000),
                        (else_try),
                            (store_character_level, ":var_59", ":var_15"),
                            (assign, ":var_58", ":var_59"),
                        (try_end),
                        (try_begin),
                            (gt, ":var_58", ":var_51"),
                            (assign, ":var_51", ":var_58"),
                            (assign, ":var_50", ":var_15"),
                            (party_stack_get_troop_dna, ":var_60", "p_main_party", ":var_28"),
                        (try_end),
                    (try_end),
                    (start_map_conversation, ":var_50", ":var_60"),
                (try_end),
            (try_end),
        (try_end),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
    ], "."),

]),

("enemy_slipped_away", 0,
"{s17}",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_total_victory"),
    ], "."),

]),

("total_defeat", 0,
"{!}You shouldn't be reading this...",
"none", 
[
    (play_track, "track_JNGL_Capture", 1),
    (party_get_num_prisoner_stacks, ":var_0", "p_main_party"),
    (try_for_range, ":var_1", 0, ":var_0"),
        (party_prisoner_stack_get_troop_id, ":var_2", "p_main_party", ":var_1"),
        (troop_is_hero, ":var_2"),
        (call_script, "script_remove_troop_from_prison", ":var_2"),
    (try_end),
    (try_begin),
        (party_is_active, "$g_ally_party"),
        (call_script, "script_battle_political_consequences", "$g_ally_party", "$g_enemy_party"),
    (else_try),
        (call_script, "script_battle_political_consequences", "p_main_party", "$g_enemy_party"),
    (try_end),
    (call_script, "script_loot_player_items", "$g_enemy_party"),
    (assign, "$g_move_heroes", 0),
    (party_clear, "p_temp_party"),
    (call_script, "script_party_add_party_prisoners", "p_temp_party", "p_main_party"),
    (call_script, "script_party_prisoners_add_party_companions", "p_temp_party", "p_main_party"),
    (distribute_party_among_party_group, "p_temp_party", "$g_enemy_party"),
    (assign, "$g_prison_heroes", 1),
    (call_script, "script_party_remove_all_companions", "p_main_party"),
    (assign, "$g_prison_heroes", 0),
    (assign, "$g_move_heroes", 1),
    (call_script, "script_party_remove_all_prisoners", "p_main_party"),
    (val_add, "$g_total_defeats", 1),
    (try_begin),
        (neg|eq, "$g_player_surrenders", 1),
        (store_random_in_range, ":var_3", 0, 100),
        (ge, ":var_3", "$g_player_luck"),
        (jump_to_menu, "mnu_permanent_damage"),
    (else_try),
        (try_begin),
            (eq, "$g_next_menu", -1),
            (leave_encounter),
            (change_screen_return),
        (else_try),
            (jump_to_menu, "$g_next_menu"),
        (try_end),
    (try_end),
    (try_begin),
        (gt, "$g_ally_party", 0),
        (call_script, "script_party_wound_all_members", "$g_ally_party"),
    (try_end),
    (party_get_num_companion_stacks, ":var_4", "p_encountered_party_backup"),
    (try_for_range, ":var_1", 0, ":var_4"),
        (party_stack_get_troop_id, ":var_2", "p_encountered_party_backup", ":var_1"),
        (is_between, ":var_2", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_2", slot_troop_occupation, 2),
        (store_troop_faction, ":var_5", ":var_2"),
        (call_script, "script_add_log_entry", 14, "trp_player", -1, ":var_2", ":var_5"),
    (try_end),
],
[
]),

("permanent_damage", 512,
"{s0}",
"none", 
[
    (assign, ":var_0", 1),
    (try_for_range, ":var_1", 0, ":var_0"),
        (store_random_in_range, ":var_2", 0, 4),
        (store_attribute_level, ":var_3", "trp_player", ":var_2"),
        (try_begin),
            (gt, ":var_3", 3),
            (neg|eq, ":var_2", 3),
            (try_begin),
                (eq, ":var_2", 0),
                (str_store_string, s0, "@Some of your tendons have been damaged in the battle. You lose 1 strength."),
            (else_try),
                (eq, ":var_2", 1),
                (str_store_string, s0, "@You took a nasty wound which will cause you to limp slightly even after it heals. You lose 1 agility."),
            (else_try),
                (str_store_string, s0, "@You have trouble thinking straight after the battle, perhaps from a particularly hard hit to your head, and frequent headaches now plague your existence. Your intelligence is reduced by 1."),
            (try_end),
        (else_try),
            (neg|ge, ":var_0", 200),
            (val_add, ":var_0", 1),
        (try_end),
    (try_end),
    (try_begin),
        (eq, ":var_0", 200),
        (try_begin),
            (eq, "$g_next_menu", -1),
            (leave_encounter),
            (change_screen_return),
        (else_try),
            (jump_to_menu, "$g_next_menu"),
        (try_end),
    (else_try),
        (troop_raise_attribute, "trp_player", ":var_2", -1),
    (try_end),
],
[
    ("s0", 
    [
        (store_random_in_range, ":var_0", 0, 4),
        (try_begin),
            (eq, ":var_0", 0),
            (str_store_string, s0, "@Perhaps I'm getting unlucky..."),
        (else_try),
            (eq, ":var_0", 1),
            (str_store_string, s0, "@Retirement is starting to sound better and better."),
        (else_try),
            (eq, ":var_0", 2),
            (str_store_string, s0, "@No matter! I will persevere!"),
        (else_try),
            (eq, ":var_0", 3),
            (troop_get_type, ":var_1", "trp_player"),
            (try_begin),
                (ge, ":var_1", 1),
                (str_store_string, s0, "@What did I do to deserve this?"),
            (else_try),
                (str_store_string, s0, "@I suppose it'll make for a good story, at least..."),
            (try_end),
        (try_end),
    ],
    "{s0}",
    [
        (try_begin),
            (eq, "$g_next_menu", -1),
            (leave_encounter),
            (change_screen_return),
        (else_try),
            (jump_to_menu, "$g_next_menu"),
        (try_end),
    ], "."),

]),

("pre_join", 0,
"You come across a battle between {s2} and {s1}. You decide to...",
"none", 
[
    (str_store_party_name, s1, "$g_encountered_party"),
    (str_store_party_name, s2, "$g_encountered_party_2"),
],
[
    ("pre_join_help_attackers", 
    [
        (store_faction_of_party, ":var_0", "$g_encountered_party_2"),
        (store_relation, ":var_1", ":var_0", "fac_player_supporters_faction"),
        (store_faction_of_party, ":var_2", "$g_encountered_party"),
        (store_relation, ":var_3", ":var_2", "fac_player_supporters_faction"),
        (ge, ":var_1", -50),
        (neg|ge, ":var_3", 80),
    ],
    "Move in to help the {s2}.",
    [
        (select_enemy, 0),
        (assign, "$g_enemy_party", "$g_encountered_party"),
        (assign, "$g_ally_party", "$g_encountered_party_2"),
        (try_begin),
            (eq, "$pop_kingdom", 1),
            (store_faction_of_party, ":var_0", "$g_encountered_party"),
            (call_script, "script_change_player_relation_with_faction", ":var_0", -10),
        (try_end),
        (jump_to_menu, "mnu_join_battle"),
    ], "."),

    ("pre_join_help_defenders", 
    [
        (store_faction_of_party, ":var_0", "$g_encountered_party_2"),
        (store_relation, ":var_1", ":var_0", "fac_player_supporters_faction"),
        (store_faction_of_party, ":var_2", "$g_encountered_party"),
        (store_relation, ":var_3", ":var_2", "fac_player_supporters_faction"),
        (ge, ":var_3", -50),
        (neg|ge, ":var_1", 80),
    ],
    "Rush to the aid of the {s1}.",
    [
        (select_enemy, 1),
        (assign, "$g_enemy_party", "$g_encountered_party_2"),
        (assign, "$g_ally_party", "$g_encountered_party"),
        (try_begin),
            (eq, "$pop_kingdom", 1),
            (store_faction_of_party, ":var_0", "$g_encountered_party_2"),
            (call_script, "script_change_player_relation_with_faction", ":var_0", -10),
        (try_end),
        (jump_to_menu, "mnu_join_battle"),
    ], "."),

    ("pre_join_leave", [],
    "Don't get involved.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("join_battle", 256,
"You are helping the {s2} against the {s1}. You have {reg10} troops fit for battle against the enemy's {reg11}.",
"none", 
[
    (str_store_party_name, s1, "$g_enemy_party"),
    (str_store_party_name, s2, "$g_ally_party"),
    (call_script, "script_encounter_calculate_fit"),
    (try_begin),
        (eq, "$new_encounter", 1),
        (assign, "$new_encounter", 0),
        (call_script, "script_encounter_init_variables"),
    (else_try),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (try_end),
    (try_begin),
        (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
        (assign, ":var_0", reg0),
        (assign, ":var_1", 0),
        (try_begin),
            (eq, "$g_battle_result", 1),
            (this_or_next|neg|gt, ":var_0", 0),
            (neg|gt, ":var_0", "$num_routed_enemies"),
            (assign, ":var_1", 1),
        (else_try),
            (eq, "$g_engaged_enemy", 1),
            (neg|gt, "$g_enemy_fit_for_battle", 0),
            (ge, "$g_friend_fit_for_battle", 1),
            (assign, ":var_1", 1),
        (try_end),
        (this_or_next|eq, ":var_1", 1),
        (eq, "$g_enemy_surrenders", 1),
        (assign, "$g_next_menu", -1),
        (jump_to_menu, "mnu_total_victory"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_collective_friends"),
        (assign, ":var_2", reg0),
        (assign, ":var_3", 0),
        (try_begin),
            (eq, "$g_battle_result", -1),
            (neg|gt, ":var_2", "$num_routed_allies"),
            (assign, ":var_3", 1),
        (try_end),
        (this_or_next|eq, ":var_3", 1),
        (eq, "$g_player_surrenders", 1),
        (leave_encounter),
        (change_screen_return),
    (try_end),
],
[
    ("game_options_reinforce", [],
    "Change battle reinforce times",
    [
        (assign, "$temp", 101),
        (start_presentation, "prsnt_numeric_input"),
    ], "."),

    ("change_commander", 
    [
        (str_store_troop_name, s7, "$g_player_troop"),
        (set_player_troop, "$g_player_troop"),
    ],
    "Change commander.(Current commander: {s7})",
    [
        (start_presentation, "prsnt_change_commander"),
    ], "."),

    ("join_attack", 
    [
        (neg|troop_is_wounded, "$g_player_troop"),
    ],
    "Charge the enemy.",
    [
        (assign, "$g_joined_battle_to_help", 1),
        (party_set_next_battle_simulation_time, "$g_encountered_party", -1),
        (assign, "$g_battle_result", 0),
        (call_script, "script_calculate_renown_value"),
        (call_script, "script_calculate_battle_advantage"),
        (set_battle_advantage, reg0),
        (set_party_battle_mode),
        (call_script, "script_set_music_for_enemy", "$g_enemy_party"),
        (try_begin),
            (eq, "$music_track_enemy", 0),
            (call_script, "script_set_music_for_enemy", "$g_ally_party"),
        (try_end),
        (set_jump_mission, "mt_lead_charge"),
        (call_script, "script_setup_random_scene"),
        (assign, "$g_next_menu", "mnu_join_battle"),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

    ("join_order_attack", 
    [
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (ge, reg0, 3),
    ],
    "Order your troops to attack with your allies while you stay back.",
    [
        (assign, "$g_joined_battle_to_help", 1),
        (party_set_next_battle_simulation_time, "$g_encountered_party", -1),
        (jump_to_menu, "mnu_join_order_attack"),
    ], "."),

    ("join_leave", [],
    "Leave.",
    [
        (try_begin),
            (neg|troop_is_wounded, "trp_player"),
            (call_script, "script_objectionable_action", 1, "str_flee_battle"),
            (party_stack_get_troop_id, ":var_0", "$g_enemy_party", 0),
            (is_between, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (call_script, "script_add_log_entry", 15, "trp_player", -1, ":var_0", -1),
        (try_end),
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("join_order_attack", 512,
"{s4}^^Your casualties: {s8}^^Allies' casualties: {s9}^^Enemy casualties: {s10}^^Allies remaining: {reg10}^Enemies remaining: {reg11}",
"none", 
[
    (call_script, "script_kt_party_calculate_strength", "p_main_party", 1, 0),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (call_script, "script_kt_party_calculate_strength_with_attachments", "$g_ally_party", 0, 0),
    (assign, ":var_2", reg0),
    (assign, ":var_3", reg1),
    (call_script, "script_kt_party_calculate_strength_with_attachments", "$g_enemy_party", 0, 0),
    (assign, ":var_4", reg0),
    (assign, ":var_5", reg1),
    (store_add, ":var_6", ":var_0", ":var_2"),
    (store_mul, ":var_7", ":var_1", ":var_0"),
    (val_mul, ":var_7", ":var_4"),
    (val_div, ":var_7", ":var_6"),
    (val_div, ":var_7", 100),
    (store_mul, ":var_8", ":var_3", ":var_2"),
    (val_mul, ":var_8", ":var_4"),
    (val_div, ":var_8", ":var_6"),
    (val_div, ":var_8", 100),
    (store_mul, ":var_9", ":var_5", ":var_6"),
    (val_div, ":var_9", 100),
    (val_div, ":var_9", 50),
    (val_div, ":var_8", 50),
    (val_div, ":var_7", 50),
    (inflict_casualties_to_party_group, "p_main_party", ":var_7", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s8, 0),
    (inflict_casualties_to_party_group, "$g_enemy_party", ":var_9", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s10, 0),
    (party_get_num_companion_stacks, ":var_10", "p_temp_casualties"),
    (try_for_range, ":var_11", 0, ":var_10"),
        (party_stack_get_troop_id, ":var_12", "p_temp_casualties", ":var_11"),
        (try_begin),
            (party_stack_get_size, ":var_13", "p_temp_casualties", ":var_11"),
            (gt, ":var_13", 0),
            (party_add_members, "p_total_enemy_casualties", ":var_12", ":var_13"),
            (party_stack_get_num_wounded, ":var_14", "p_temp_casualties", ":var_11"),
            (gt, ":var_14", 0),
            (party_wound_members, "p_total_enemy_casualties", ":var_12", ":var_14"),
        (try_end),
    (try_end),
    (call_script, "script_collect_friendly_parties"),
    (inflict_casualties_to_party_group, "$g_ally_party", ":var_8", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s9, 0),
    (party_collect_attachments_to_party, "$g_enemy_party", "p_collective_enemy"),
    (assign, "$no_soldiers_left", 0),
    (try_begin),
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (assign, ":var_15", reg0),
        (neg|gt, ":var_15", "$num_routed_us"),
        (assign, "$no_soldiers_left", 1),
        (str_store_string, s4, "str_join_order_attack_failure"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
        (assign, ":var_16", reg0),
        (this_or_next|neg|gt, ":var_16", 0),
        (neg|gt, ":var_16", "$num_routed_enemies"),
        (assign, "$g_battle_result", 1),
        (assign, "$no_soldiers_left", 1),
        (str_store_string, s4, "str_join_order_attack_success"),
    (else_try),
        (str_store_string, s4, "str_join_order_attack_continue"),
    (try_end),
    (call_script, "script_encounter_calculate_fit"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_join_battle"),
    ], "."),

]),

("salt_mine", 16,
"You enter the Hidden mines of Al-Aziz.",
"none", 
[
    (reset_price_rates, 0),
    (set_price_rate_for_item, "itm_salt", 55),
],
[
    ("enter", [],
    "Enter.",
    [
        (set_jump_mission, "mt_town_center"),
        (jump_to_scene, "scn_salt_mine"),
        (change_screen_mission),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("four_ways_inn", 16,
"You arrive at the Four Ways Inn.",
"none", [],
[
    ("enter", [],
    "Enter.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_four_ways_inn"),
        (change_screen_mission),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("test_scene", 0,
"You enter the test scene.",
"none", [],
[
    ("enter", [],
    "Enter 1.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_multi_scene_1"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 2.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_multi_scene_2"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 3.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_multi_scene_3"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 4.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_multi_scene_4"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 5.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_multi_scene_5"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 6.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_multi_scene_6"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 7.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_test2"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 8.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_test3"),
        (change_screen_mission),
    ], "."),

    ("enter", [],
    "Enter 9.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_multi_scene_13"),
        (change_screen_mission),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("battlefields", 0,
"{!}Select a field...",
"none", [],
[
    ("enter_f1", [],
    "{!}Field 1",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_field_1"),
        (change_screen_mission),
    ], "."),

    ("enter_f2", [],
    "{!}Field 2",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_field_2"),
        (change_screen_mission),
    ], "."),

    ("enter_f3", [],
    "{!}Field 3",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_field_3"),
        (change_screen_mission),
    ], "."),

    ("enter_f4", [],
    "{!}Field 4",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_field_4"),
        (change_screen_mission),
    ], "."),

    ("enter_f5", [],
    "{!}Field 5",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "scn_field_5"),
        (change_screen_mission),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("dhorak_keep", 0,
"You enter the Dhorak Keep",
"none", [],
[
    ("enter", [],
    "Enter.",
    [
        (set_jump_mission, "mt_town_center"),
        (jump_to_scene, "scn_dhorak_keep"),
        (change_screen_mission),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("join_siege_outside", 4096,
"{s1} has come under siege by {s2}.",
"none", 
[
    (str_store_party_name, s1, "$g_encountered_party"),
    (str_store_party_name, s2, "$g_encountered_party_2"),
    (troop_get_type, ":var_0", "$g_player_troop"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_siege_sighted_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_siege_sighted"),
    (try_end),
],
[
    ("approach_besiegers", 
    [
        (store_faction_of_party, ":var_0", "$g_encountered_party_2"),
        (store_relation, ":var_1", ":var_0", "fac_player_supporters_faction"),
        (ge, ":var_1", 0),
        (store_faction_of_party, ":var_0", "$g_encountered_party"),
        (store_relation, ":var_1", ":var_0", "fac_player_supporters_faction"),
        (neg|ge, ":var_1", 0),
    ],
    "Approach the siege camp.",
    [
        (jump_to_menu, "mnu_besiegers_camp_with_allies"),
    ], "."),

    ("pass_through_siege", 
    [
        (store_faction_of_party, ":var_0", "$g_encountered_party"),
        (store_relation, ":var_1", ":var_0", "fac_player_supporters_faction"),
        (ge, ":var_1", 0),
    ],
    "Pass through the siege lines and enter {s1}.",
    [
        (jump_to_menu, "mnu_cut_siege_without_fight"),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("cut_siege_without_fight", 0,
"The besiegers let you approach the gates without challenge.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
            (this_or_next|eq, "$g_encountered_party_faction", "fac_player_supporters_faction"),
            (eq, "$g_encountered_party_faction", "$players_kingdom"),
            (jump_to_menu, "mnu_town"),
        (else_try),
            (jump_to_menu, "mnu_castle_outside"),
        (try_end),
    ], "."),

]),

("besiegers_camp_with_allies", 256,
"{s1} remains under siege. The banners of {s2} fly above the camp of the besiegers, where you and your men are welcomed.",
"none", 
[
    (str_store_party_name, s1, "$g_encountered_party"),
    (str_store_party_name, s2, "$g_encountered_party_2"),
    (assign, "$g_enemy_party", "$g_encountered_party"),
    (assign, "$g_ally_party", "$g_encountered_party_2"),
    (select_enemy, 0),
    (call_script, "script_encounter_calculate_fit"),
    (try_begin),
        (eq, "$new_encounter", 1),
        (assign, "$new_encounter", 0),
        (call_script, "script_encounter_init_variables"),
    (try_end),
    (try_begin),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (else_try),
        (assign, ":var_0", 0),
        (try_begin),
            (eq, "$g_battle_result", 1),
            (assign, ":var_0", 1),
        (else_try),
            (neg|gt, "$g_enemy_fit_for_battle", 0),
            (ge, "$g_friend_fit_for_battle", 1),
            (assign, ":var_0", 1),
        (try_end),
        (this_or_next|eq, ":var_0", 1),
        (eq, "$g_enemy_surrenders", 1),
        (call_script, "script_party_wound_all_members", "$g_enemy_party"),
        (leave_encounter),
        (change_screen_return),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_collective_friends"),
        (assign, ":var_1", reg0),
        (eq, "$g_battle_result", -1),
        (eq, ":var_1", 0),
        (leave_encounter),
        (change_screen_return),
    (try_end),
],
[
    ("talk_to_siege_commander", 
    [
        (party_stack_get_troop_id, ":var_0", "$g_encountered_party_2", 0),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
    ],
    " Request a meeting with the commander.",
    [
        (call_script, "script_get_meeting_scene"),
        (assign, ":var_0", reg0),
        (modify_visitors_at_site, ":var_0"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (party_stack_get_troop_id, ":var_1", "$g_encountered_party_2", 0),
        (party_stack_get_troop_dna, ":var_2", "$g_encountered_party_2", 0),
        (set_visitor, 17, ":var_1", ":var_2"),
        (set_jump_mission, "mt_conversation_encounter"),
        (jump_to_scene, ":var_0"),
        (assign, "$talk_context", 4),
        (change_screen_map_conversation, ":var_1"),
    ], "."),

    ("change_commander", 
    [
        (str_store_troop_name, s7, "$g_player_troop"),
        (set_player_troop, "$g_player_troop"),
    ],
    "Change commander.(Current commander: {s7})",
    [
        (start_presentation, "prsnt_change_commander"),
    ], "."),

    ("join_siege_with_allies", 
    [
        (neg|troop_is_wounded, "$g_player_troop"),
    ],
    "Join the next assault.",
    [
        (assign, "$g_joined_battle_to_help", 1),
        (party_set_next_battle_simulation_time, "$g_encountered_party", -1),
        (try_begin),
            (check_quest_active, "qst_join_siege_with_army"),
            (quest_slot_eq, "qst_join_siege_with_army", 1, "$g_encountered_party"),
            (add_xp_as_reward, 250),
            (call_script, "script_end_quest", "qst_join_siege_with_army"),
            (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_marshall),
            (str_store_troop_name_link, s9, ":var_0"),
            (setup_quest_text, "qst_follow_army"),
            (str_store_string, s2, "@{s9} wants you to follow his army until further notice."),
            (call_script, "script_start_quest", "qst_follow_army", ":var_0"),
            (assign, "$g_player_follow_army_warnings", 0),
        (try_end),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (party_get_slot, ":var_1", "$g_encountered_party", slot_town_walls),
        (else_try),
            (party_get_slot, ":var_1", "$g_encountered_party", slot_town_center),
        (try_end),
        (call_script, "script_calculate_renown_value"),
        (call_script, "script_calculate_battle_advantage"),
        (val_mul, reg0, 2),
        (val_div, reg0, 3),
        (set_battle_advantage, reg0),
        (set_party_battle_mode),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_center_siege_with_belfry, 1),
            (set_jump_mission, "mt_castle_attack_walls_belfry"),
        (else_try),
            (set_jump_mission, "mt_castle_attack_walls_ladder"),
        (try_end),
        (jump_to_scene, ":var_1"),
        (assign, "$g_siege_final_menu", "mnu_besiegers_camp_with_allies"),
        (assign, "$g_siege_battle_state", 1),
        (assign, "$g_next_menu", "mnu_castle_besiege_inner_battle"),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

    ("join_siege_stay_back", 
    [
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (ge, reg0, 3),
    ],
    "Order your soldiers to join the next assault without you.",
    [
        (assign, "$g_joined_battle_to_help", 1),
        (party_set_next_battle_simulation_time, "$g_encountered_party", -1),
        (try_begin),
            (check_quest_active, "qst_join_siege_with_army"),
            (quest_slot_eq, "qst_join_siege_with_army", 1, "$g_encountered_party"),
            (add_xp_as_reward, 100),
            (call_script, "script_end_quest", "qst_join_siege_with_army"),
            (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_marshall),
            (str_store_troop_name_link, s9, ":var_0"),
            (setup_quest_text, "qst_follow_army"),
            (str_store_string, s2, "@{s9} wants you to follow his army until further notice."),
            (call_script, "script_start_quest", "qst_follow_army", ":var_0"),
            (assign, "$g_player_follow_army_warnings", 0),
        (try_end),
        (jump_to_menu, "mnu_castle_attack_walls_with_allies_simulate"),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (leave_encounter),
        (change_screen_return),
    ], "."),

]),

("castle_outside", 4096,
"You are outside {s2}.{s11} {s3} {s4}",
"none", 
[
    (assign, "$g_enemy_party", "$g_encountered_party"),
    (assign, "$g_ally_party", -1),
    (str_store_party_name, s2, "$g_encountered_party"),
    (call_script, "script_encounter_calculate_fit"),
    (assign, "$all_doors_locked", 1),
    (assign, "$current_town", "$g_encountered_party"),
    (try_begin),
        (eq, "$new_encounter", 1),
        (assign, "$new_encounter", 0),
        (call_script, "script_let_nearby_parties_join_current_battle", 1, 0),
        (call_script, "script_encounter_init_variables"),
        (assign, "$entry_to_town_forbidden", 0),
        (assign, "$sneaked_into_town", 0),
        (assign, "$town_entered", 0),
        (assign, "$encountered_party_hostile", 0),
        (assign, "$encountered_party_friendly", 0),
        (try_begin),
            (gt, "$g_player_besiege_town", 0),
            (neg|eq, "$g_player_besiege_town", "$g_encountered_party"),
            (party_slot_eq, "$g_player_besiege_town", slot_center_is_besieged_by, "p_main_party"),
            (call_script, "script_lift_siege", "$g_player_besiege_town", 0),
            (assign, "$g_player_besiege_town", -1),
        (try_end),
        (try_begin),
            (neg|ge, "$g_encountered_party_relation", 0),
            (assign, "$encountered_party_hostile", 1),
            (assign, "$entry_to_town_forbidden", 1),
        (try_end),
        (assign, "$cant_sneak_into_town", 0),
        (try_begin),
            (eq, "$current_town", "$last_sneak_attempt_town"),
            (store_current_hours, reg2),
            (val_sub, reg2, "$last_sneak_attempt_time"),
            (neg|ge, reg2, 12),
            (assign, "$cant_sneak_into_town", 1),
        (try_end),
    (else_try),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (try_end),
    (str_clear, s4),
    (try_begin),
        (eq, "$entry_to_town_forbidden", 1),
        (try_begin),
            (eq, "$cant_sneak_into_town", 1),
            (str_store_string, s4, "str_sneaking_to_town_impossible"),
        (else_try),
            (str_store_string, s4, "str_entrance_to_town_forbidden"),
        (try_end),
    (try_end),
    (party_get_slot, ":var_0", "$current_town", slot_town_lord),
    (store_faction_of_party, ":var_1", "$current_town"),
    (str_store_faction_name, s9, ":var_1"),
    (try_begin),
        (ge, ":var_0", 0),
        (str_store_troop_name, s8, ":var_0"),
        (str_store_string, s7, "@{s8} of the {s9}"),
    (try_end),
    (try_begin),
        (party_slot_eq, "$current_town", slot_party_type, 2),
        (try_begin),
            (eq, ":var_0", "trp_player"),
            (str_store_string, s11, "@ Your own banner flies over the castle gate."),
        (else_try),
            (ge, ":var_0", 0),
            (str_store_string, s11, "@ You see the banner of {s7} over the castle gate."),
        (else_try),
            (is_between, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (str_store_string, s11, "str__this_castle_is_temporarily_under_royal_control"),
        (else_try),
            (str_store_string, s11, "str__this_castle_does_not_seem_to_be_under_anyones_control"),
        (try_end),
    (else_try),
        (try_begin),
            (eq, ":var_0", "trp_player"),
            (str_store_string, s11, "@ Your own banner flies over the town gates."),
        (else_try),
            (ge, ":var_0", 0),
            (str_store_string, s11, "@ You see the banner of {s7} over the town gates."),
        (else_try),
            (is_between, ":var_1", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (str_store_string, s11, "str__this_town_is_temporarily_under_royal_control"),
        (else_try),
            (str_store_string, s11, "str__the_townspeople_seem_to_have_declared_their_independence"),
        (try_end),
    (try_end),
    (party_get_num_companions, reg7, "p_collective_enemy"),
    (assign, "$castle_undefended", 0),
    (str_clear, s3),
    (try_begin),
        (eq, reg7, 0),
        (assign, "$castle_undefended", 1),
        (str_store_string, s3, "str_castle_is_abondened"),
    (else_try),
        (eq, "$g_encountered_party_faction", "fac_player_supporters_faction"),
        (str_store_string, s3, "str_place_is_occupied_by_player"),
    (else_try),
        (neg|ge, "$g_encountered_party_relation", 0),
        (str_store_string, s3, "str_place_is_occupied_by_enemy"),
    (else_try),
    (try_end),
    (try_begin),
        (eq, "$g_leave_town_outside", 1),
        (assign, "$g_leave_town_outside", 0),
        (assign, "$g_permitted_to_center", 0),
        (change_screen_return),
    (else_try),
        (check_quest_active, "qst_escort_lady"),
        (quest_slot_eq, "qst_escort_lady", 1, "$g_encountered_party"),
        (quest_get_slot, ":var_2", "qst_escort_lady", 4),
        (call_script, "script_get_meeting_scene"),
        (assign, ":var_3", reg0),
        (modify_visitors_at_site, ":var_3"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 17, ":var_2"),
        (set_jump_mission, "mt_conversation_encounter"),
        (jump_to_scene, ":var_3"),
        (assign, "$talk_context", 10),
        (change_screen_map_conversation, ":var_2"),
    (else_try),
        (check_quest_active, "qst_kidnapped_girl"),
        (quest_slot_eq, "qst_kidnapped_girl", 12, "$g_encountered_party"),
        (quest_slot_eq, "qst_kidnapped_girl", 11, 3),
        (call_script, "script_get_meeting_scene"),
        (assign, ":var_3", reg0),
        (modify_visitors_at_site, ":var_3"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 17, "trp_kidnapped_girl"),
        (set_jump_mission, "mt_conversation_encounter"),
        (jump_to_scene, ":var_3"),
        (assign, "$talk_context", 10),
        (change_screen_map_conversation, "trp_kidnapped_girl"),
    (else_try),
        (eq, "$g_town_visit_after_rest", 1),
        (assign, "$g_town_visit_after_rest", 0),
        (jump_to_menu, "mnu_town"),
    (else_try),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_town_lord, "trp_player"),
        (faction_slot_eq, "$g_encountered_party_faction", slot_faction_leader, "trp_player"),
        (jump_to_menu, "mnu_enter_your_own_castle"),
    (else_try),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (ge, "$g_encountered_party_relation", 0),
        (this_or_next|eq, "$castle_undefended", 1),
        (this_or_next|eq, "$g_permitted_to_center", 1),
        (eq, "$g_encountered_party_faction", "$players_kingdom"),
        (jump_to_menu, "mnu_town"),
    (else_try),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (ge, "$g_encountered_party_relation", 0),
        (jump_to_menu, "mnu_town"),
    (else_try),
        (eq, "$g_player_besiege_town", "$g_encountered_party"),
        (jump_to_menu, "mnu_castle_besiege"),
    (try_end),
    (call_script, "script_set_town_picture"),
],
[
    ("approach_gates", 
    [
        (this_or_next|eq, "$entry_to_town_forbidden", 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
    ],
    "Approach the gates and hail the guard.",
    [
        (jump_to_menu, "mnu_castle_guard"),
    ], "."),

    ("town_sneak", 
    [
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (str_store_string, s7, "str_town"),
        (else_try),
            (str_store_string, s7, "str_castle"),
        (try_end),
        (eq, "$entry_to_town_forbidden", 1),
        (eq, "$cant_sneak_into_town", 0),
    ],
    "Disguise yourself and try to sneak into the {s7}",
    [
        (faction_get_slot, ":var_0", "$g_encountered_party_faction", slot_faction_player_alarm),
        (party_get_num_companions, ":var_1", "p_main_party"),
        (party_get_num_prisoners, ":var_2", "p_main_party"),
        (val_add, ":var_1", ":var_2"),
        (val_mul, ":var_1", 2),
        (val_div, ":var_1", 3),
        (store_add, ":var_3", ":var_0", ":var_1"),
        (store_random_in_range, ":var_4", 0, 100),
        (try_begin),
            (this_or_next|ge, ":var_4", ":var_3"),
            (eq, "$g_last_defeated_bandits_town", "$g_encountered_party"),
            (assign, "$g_last_defeated_bandits_town", 0),
            (assign, "$sneaked_into_town", 1),
            (assign, "$town_entered", 1),
            (jump_to_menu, "mnu_sneak_into_town_suceeded"),
            (assign, "$g_mt_mode", 1),
        (else_try),
            (jump_to_menu, "mnu_sneak_into_town_caught"),
        (try_end),
    ], "."),

    ("castle_start_siege", 
    [
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_center_is_besieged_by, -1),
        (party_slot_eq, "$g_encountered_party", slot_center_is_besieged_by, "p_main_party"),
        (store_relation, ":var_0", "$g_encountered_party_faction", "fac_player_supporters_faction"),
        (neg|ge, ":var_0", 0),
        (neg|ge, "$g_encountered_party_2", 1),
        (call_script, "script_party_count_fit_for_battle", "p_main_party"),
        (gt, reg0, 5),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (assign, reg6, 1),
        (else_try),
            (assign, reg6, 0),
        (try_end),
    ],
    "Besiege the {reg6?town:castle}.",
    [
        (assign, "$g_player_besiege_town", "$g_encountered_party"),
        (store_relation, ":var_0", "fac_player_supporters_faction", "$g_encountered_party_faction"),
        (val_min, ":var_0", -40),
        (call_script, "script_set_player_relation_with_faction", "$g_encountered_party_faction", ":var_0"),
        (call_script, "script_update_all_notes"),
        (jump_to_menu, "mnu_castle_besiege"),
    ], "."),

    ("cheat_castle_start_siege", 
    [
        (eq, "$cheat_mode", 1),
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_center_is_besieged_by, -1),
        (party_slot_eq, "$g_encountered_party", slot_center_is_besieged_by, "p_main_party"),
        (store_relation, ":var_0", "$g_encountered_party_faction", "fac_player_supporters_faction"),
        (ge, ":var_0", 0),
        (neg|ge, "$g_encountered_party_2", 1),
        (call_script, "script_party_count_fit_for_battle", "p_main_party"),
        (gt, reg0, 1),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (assign, reg6, 1),
        (else_try),
            (assign, reg6, 0),
        (try_end),
    ],
    "{!}CHEAT: Besiege the {reg6?town:castle}...",
    [
        (assign, "$g_player_besiege_town", "$g_encountered_party"),
        (jump_to_menu, "mnu_castle_besiege"),
    ], "."),

    ("castle_leave", [],
    "Leave.",
    [
        (change_screen_return, 0),
    ], "."),

    ("castle_cheat_interior", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! Interior.",
    [
        (set_jump_mission, "mt_ai_training"),
        (party_get_slot, ":var_0", "$current_town", slot_town_castle),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("castle_cheat_exterior", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! Exterior.",
    [
        (set_jump_mission, "mt_ai_training"),
        (party_get_slot, ":var_0", "$current_town", slot_town_center),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("castle_cheat_town_walls", 
    [
        (eq, "$cheat_mode", 1),
        (party_slot_eq, "$current_town", slot_party_type, 3),
    ],
    "{!}CHEAT! Town Walls.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_walls),
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

]),

("castle_guard", 4096,
"You approach the gate. The men on the walls watch you closely.",
"none", 
[
    (call_script, "script_set_town_picture"),
],
[
    ("request_shelter", 
    [
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (ge, "$g_encountered_party_relation", 0),
    ],
    "Request entry to the castle.",
    [
        (party_get_slot, ":var_0", "$g_encountered_party", slot_town_lord),
        (try_begin),
            (neg|ge, ":var_0", 0),
            (jump_to_menu, "mnu_castle_entry_granted"),
        (else_try),
            (call_script, "script_troop_get_player_relation", ":var_0"),
            (assign, ":var_1", reg0),
            (try_begin),
                (gt, ":var_1", -15),
                (jump_to_menu, "mnu_castle_entry_granted"),
            (else_try),
                (jump_to_menu, "mnu_castle_entry_denied"),
            (try_end),
        (try_end),
    ], "."),

    ("request_meeting_commander", [],
    "Request a meeting with someone.",
    [
        (jump_to_menu, "mnu_castle_meeting"),
    ], "."),

    ("guard_leave", [],
    "Leave.",
    [
        (change_screen_return, 0),
    ], "."),

]),

("castle_entry_granted", 4096,
"After a brief wait, the guards open the gates for you and allow your party inside.",
"none", 
[
    (call_script, "script_set_town_picture"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("castle_entry_denied", 4096,
"The lord of this castle has forbidden you from coming inside these walls, and the guard sergeant informs you that his men will fire if you attempt to come any closer.",
"none", 
[
    (call_script, "script_set_town_picture"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_castle_guard"),
    ], "."),

]),

("castle_meeting", 4096,
"With whom do you want to meet?",
"none", 
[
    (assign, "$num_castle_meeting_troops", 0),
    (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (call_script, "script_get_troop_attached_party", ":var_0"),
        (eq, "$g_encountered_party", reg0),
        (troop_set_slot, "trp_temp_array_a", "$num_castle_meeting_troops", ":var_0"),
        (val_add, "$num_castle_meeting_troops", 1),
    (try_end),
    (call_script, "script_set_town_picture"),
],
[
    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 0),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_relations_begin),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_relations_begin),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 1),
        (troop_get_slot, ":var_0", "trp_temp_array_a", 1),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", 1),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 2),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_occupation),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_occupation),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 3),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_state),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_state),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 4),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_last_talk_time),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_last_talk_time),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 5),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_met),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_met),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 6),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_party_template),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_party_template),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 7),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_renown),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_renown),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 8),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_prisoner_of_party),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_prisoner_of_party),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("guard_meet_s5", 
    [
        (gt, "$num_castle_meeting_troops", 9),
        (troop_get_slot, ":var_0", "trp_temp_array_a", slot_troop_present_at_event),
        (str_store_troop_name, s5, ":var_0"),
    ],
    "{s5}.",
    [
        (troop_get_slot, "$castle_meeting_selected_troop", "trp_temp_array_a", slot_troop_present_at_event),
        (jump_to_menu, "mnu_castle_meeting_selected"),
    ], "."),

    ("forget_it", [],
    "Forget it.",
    [
        (jump_to_menu, "mnu_castle_guard"),
    ], "."),

]),

("castle_meeting_selected", 0,
"Your request for a meeting is relayed inside, and finally {s6} appears in the courtyard to speak with you.",
"none", 
[
    (str_store_troop_name, s6, "$castle_meeting_selected_troop"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_castle_outside"),
        (modify_visitors_at_site, "scn_conversation_scene"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 17, "$castle_meeting_selected_troop"),
        (set_jump_mission, "mt_conversation_encounter"),
        (jump_to_scene, "scn_conversation_scene"),
        (assign, "$talk_context", 3),
        (change_screen_map_conversation, "$castle_meeting_selected_troop"),
    ], "."),

]),

("castle_besiege", 4352,
"You are laying siege to {s1}. {s2} {s3}",
"none", 
[
    (troop_get_type, ":var_0", "$g_player_troop"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_siege_sighted_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_siege_sighted"),
    (try_end),
    (assign, "$g_siege_force_wait", 0),
    (try_begin),
        (party_slot_eq, "$g_encountered_party", slot_center_is_besieged_by, -1),
        (party_set_slot, "$g_encountered_party", slot_center_is_besieged_by, "p_main_party"),
        (store_current_hours, ":var_1"),
        (party_set_slot, "$g_encountered_party", slot_center_siege_begin_hours, ":var_1"),
        (assign, "$g_siege_method", 0),
        (assign, "$g_siege_sallied_out_once", 0),
    (try_end),
    (party_get_slot, ":var_2", "$g_encountered_party", slot_party_food_store),
    (call_script, "script_center_get_food_consumption", "$g_encountered_party"),
    (assign, ":var_3", reg0),
    (assign, reg7, ":var_3"),
    (assign, reg8, ":var_2"),
    (store_div, reg3, ":var_2", ":var_3"),
    (try_begin),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (assign, reg6, 1),
    (else_try),
        (assign, reg6, 0),
    (try_end),
    (try_begin),
        (gt, reg3, 0),
        (str_store_string, s2, "@The {reg6?town's:castle's} food stores should last for {reg3} more days."),
    (else_try),
        (str_store_string, s2, "@The {reg6?town's:castle's} food stores have run out and the defenders are starving."),
    (try_end),
    (str_store_string, s3, "str_empty_string"),
    (try_begin),
        (ge, "$g_siege_method", 1),
        (store_current_hours, ":var_1"),
        (try_begin),
            (neg|ge, ":var_1", "$g_siege_method_finish_hours"),
            (store_sub, reg9, "$g_siege_method_finish_hours", ":var_1"),
            (try_begin),
                (eq, "$g_siege_method", 1),
                (str_store_string, s3, "@You're preparing to attack the walls, the work should finish in {reg9} hours."),
            (else_try),
                (eq, "$g_siege_method", 2),
                (str_store_string, s3, "@Your forces are building a siege tower. They estimate another {reg9} hours to complete the build."),
            (try_end),
        (else_try),
            (try_begin),
                (eq, "$g_siege_method", 1),
                (str_store_string, s3, "@You are ready to attack the walls at any time."),
            (else_try),
                (eq, "$g_siege_method", 2),
                (str_store_string, s3, "@The siege tower is built and ready to make an assault."),
            (try_end),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$g_castle_left_to_player", 1),
        (assign, "$g_castle_left_to_player", 0),
        (store_faction_of_party, ":var_4", "$g_encountered_party"),
        (party_set_faction, "$g_encountered_party", "fac_neutral"),
        (party_get_num_attached_parties, ":var_5", "$g_encountered_party"),
        (try_for_range_backwards, ":var_6", 0, ":var_5"),
            (party_get_attached_party_with_rank, ":var_7", "$g_encountered_party", ":var_6"),
            (party_detach, ":var_7"),
            (party_get_slot, ":var_8", ":var_7", slot_party_type),
            (eq, ":var_8", 13),
            (store_faction_of_party, ":var_9", ":var_7"),
            (call_script, "script_get_closest_walled_center_of_faction", ":var_7", ":var_9"),
            (try_begin),
                (gt, reg0, 0),
                (call_script, "script_party_set_ai_state", ":var_7", 7, reg0),
            (else_try),
                (call_script, "script_party_set_ai_state", ":var_7", 4, "$g_encountered_party"),
            (try_end),
        (try_end),
        (call_script, "script_party_remove_all_companions", "$g_encountered_party"),
        (change_screen_return),
        (party_collect_attachments_to_party, "$g_encountered_party", "p_collective_enemy"),
        (call_script, "script_party_copy", "p_encountered_party_backup", "p_collective_enemy"),
        (party_set_faction, "$g_encountered_party", ":var_4"),
    (try_end),
    (assign, "$g_enemy_party", "$g_encountered_party"),
    (assign, "$g_ally_party", -1),
    (str_store_party_name, s1, "$g_encountered_party"),
    (call_script, "script_encounter_calculate_fit"),
    (assign, reg11, "$g_enemy_fit_for_battle"),
    (assign, reg10, "$g_friend_fit_for_battle"),
    (try_begin),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (else_try),
        (call_script, "script_party_count_fit_regulars", "p_collective_enemy"),
        (assign, ":var_10", 0),
        (try_begin),
            (eq, "$g_battle_result", 1),
            (assign, ":var_10", 1),
        (else_try),
            (neg|gt, "$g_enemy_fit_for_battle", 0),
            (ge, "$g_friend_fit_for_battle", 1),
            (assign, ":var_10", 1),
        (try_end),
        (this_or_next|eq, ":var_10", 1),
        (eq, "$g_enemy_surrenders", 1),
        (assign, "$g_next_menu", "mnu_castle_taken"),
        (jump_to_menu, "mnu_total_victory"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (assign, ":var_11", reg0),
        (eq, "$g_battle_result", -1),
        (eq, ":var_11", 0),
        (assign, "$g_next_menu", "mnu_captivity_start_castle_defeat"),
        (jump_to_menu, "mnu_total_defeat"),
    (try_end),
],
[
    ("siege_request_meeting", 
    [
        (eq, "$cant_talk_to_enemy", 0),
    ],
    "Call for a meeting with the castle commander.",
    [
        (assign, "$cant_talk_to_enemy", 1),
        (assign, "$g_enemy_surrenders", 0),
        (assign, "$g_castle_left_to_player", 0),
        (assign, "$talk_context", 7),
        (party_get_num_attached_parties, ":var_0", "$g_encountered_party"),
        (try_begin),
            (gt, ":var_0", 0),
            (party_get_attached_party_with_rank, ":var_1", "$g_encountered_party", 0),
            (call_script, "script_setup_party_meeting", ":var_1"),
        (else_try),
            (call_script, "script_setup_party_meeting", "$g_encountered_party"),
        (try_end),
    ], "."),

    ("wait_24_hours", [],
    "Wait until tomorrow.",
    [
        (assign, "$auto_besiege_town", "$g_encountered_party"),
        (assign, "$g_siege_force_wait", 1),
        (store_time_of_day, ":var_0"),
        (val_add, ":var_0", 1),
        (assign, ":var_1", 31),
        (val_sub, ":var_1", ":var_0"),
        (val_mod, ":var_1", 24),
        (val_add, ":var_1", 1),
        (rest_for_hours_interactive, ":var_1", 5, 1),
        (assign, "$cant_talk_to_enemy", 0),
        (change_screen_return),
    ], "."),

    ("change_commander", 
    [
        (ge, "$g_siege_method", 1),
        (store_current_hours, ":var_0"),
        (ge, ":var_0", "$g_siege_method_finish_hours"),
        (str_store_troop_name, s7, "$g_player_troop"),
        (set_player_troop, "$g_player_troop"),
    ],
    "Change commander.(Current commander: {s7})",
    [
        (start_presentation, "prsnt_change_commander"),
    ], "."),

    ("castle_lead_attack", 
    [
        (neg|troop_is_wounded, "$g_player_troop"),
        (ge, "$g_siege_method", 1),
        (gt, "$g_friend_fit_for_battle", 3),
        (store_current_hours, ":var_0"),
        (ge, ":var_0", "$g_siege_method_finish_hours"),
    ],
    "Lead your soldiers in an assault.",
    [
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (party_get_slot, ":var_0", "$g_encountered_party", slot_town_walls),
        (else_try),
            (party_get_slot, ":var_0", "$g_encountered_party", slot_town_center),
        (try_end),
        (call_script, "script_calculate_renown_value"),
        (call_script, "script_calculate_battle_advantage"),
        (assign, ":var_1", reg0),
        (val_mul, ":var_1", 2),
        (val_div, ":var_1", 3),
        (assign, reg0, ":var_1"),
        (call_script, "script_sally_count_archers_fit_for_battle", "p_collective_friends"),
        (assign, ":var_2", reg1),
        (call_script, "script_sally_count_archers_fit_for_battle", "p_collective_enemy"),
        (assign, ":var_3", reg1),
        (assign, ":var_4", reg0),
        (set_battle_advantage, ":var_1"),
        (set_party_battle_mode),
        (assign, "$g_siege_battle_state", 1),
        (assign, ":var_5", 0),
        (try_begin),
            (neg|gt, ":var_1", -4),
            (eq, "$g_siege_sallied_out_once", 0),
            (set_jump_mission, "mt_castle_attack_walls_defenders_sally"),
            (assign, "$g_siege_battle_state", 0),
            (assign, ":var_5", 1),
        (else_try),
            (eq, "$g_siege_sallied_out_once", 0),
            (neg|gt, ":var_1", -3),
            (this_or_next|ge, ":var_2", 33),
            (neg|gt, ":var_3", 20),
            (set_jump_mission, "mt_castle_attack_walls_defenders_sally"),
            (assign, "$g_siege_battle_state", 0),
            (assign, ":var_5", 1),
        (else_try),
            (eq, "$g_siege_sallied_out_once", 0),
            (neg|gt, ":var_1", -2),
            (ge, ":var_4", 80),
            (this_or_next|ge, ":var_2", 50),
            (neg|gt, ":var_3", 20),
            (set_jump_mission, "mt_castle_attack_walls_defenders_sally"),
            (assign, "$g_siege_battle_state", 0),
            (assign, ":var_5", 1),
        (else_try),
            (eq, "$g_siege_sallied_out_once", 0),
            (neg|gt, ":var_1", 0),
            (store_add, ":var_6", ":var_2", ":var_3"),
            (val_mul, ":var_2", 100),
            (val_div, ":var_2", ":var_6"),
            (ge, ":var_2", 70),
            (ge, ":var_4", 150),
            (set_jump_mission, "mt_castle_attack_walls_defenders_sally"),
            (assign, "$g_siege_battle_state", 0),
            (assign, ":var_5", 1),
        (else_try),
            (party_slot_eq, "$current_town", slot_center_siege_with_belfry, 1),
            (set_jump_mission, "mt_castle_attack_walls_belfry"),
        (else_try),
            (set_jump_mission, "mt_castle_attack_walls_ladder"),
        (try_end),
        (assign, "$cant_talk_to_enemy", 0),
        (assign, "$g_siege_final_menu", "mnu_castle_besiege"),
        (assign, "$g_next_menu", "mnu_castle_besiege_inner_battle"),
        (assign, "$g_siege_method", 0),
        (jump_to_scene, ":var_0"),
        (try_begin),
            (eq, ":var_5", 1),
            (jump_to_menu, "mnu_siege_attack_meets_sally"),
        (else_try),
            (jump_to_menu, "mnu_battle_debrief"),
            (change_screen_mission),
        (try_end),
    ], "."),

    ("attack_stay_back", 
    [
        (ge, "$g_siege_method", 1),
        (gt, "$g_friend_fit_for_battle", 3),
        (store_current_hours, ":var_0"),
        (ge, ":var_0", "$g_siege_method_finish_hours"),
    ],
    "Order your soldiers to attack while you stay back...",
    [
        (assign, "$cant_talk_to_enemy", 0),
        (jump_to_menu, "mnu_castle_attack_walls_simulate"),
    ], "."),

    ("build_ladders", 
    [
        (party_slot_eq, "$current_town", slot_center_siege_with_belfry, 0),
        (eq, "$g_siege_method", 0),
    ],
    "Prepare ladders to attack the walls.",
    [
        (jump_to_menu, "mnu_construct_ladders"),
    ], "."),

    ("build_siege_tower", 
    [
        (party_slot_eq, "$current_town", slot_center_siege_with_belfry, 1),
        (eq, "$g_siege_method", 0),
    ],
    "Build a siege tower.",
    [
        (jump_to_menu, "mnu_construct_siege_tower"),
    ], "."),

    ("cheat_castle_lead_attack", 
    [
        (eq, "$cheat_mode", 1),
        (eq, "$g_siege_method", 0),
    ],
    "{!}CHEAT: Instant build equipments.",
    [
        (assign, "$g_siege_method", 1),
        (assign, "$g_siege_method_finish_hours", 0),
        (jump_to_menu, "mnu_castle_besiege"),
    ], "."),

    ("cheat_conquer_castle", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT: Instant conquer castle.",
    [
        (assign, "$g_next_menu", "mnu_castle_taken"),
        (jump_to_menu, "mnu_total_victory"),
    ], "."),

    ("lift_siege", [],
    "Abandon the siege.",
    [
        (call_script, "script_lift_siege", "$g_player_besiege_town", 0),
        (assign, "$g_player_besiege_town", -1),
        (change_screen_return),
    ], "."),

]),

("siege_attack_meets_sally", 4096,
"The defenders sally out to meet your assault.",
"none", 
[
    (set_background_mesh, "mesh_pic_sally_out"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

]),

("castle_besiege_inner_battle", 4096,
"{s1}",
"none", 
[
    (troop_get_type, ":var_0", "$g_player_troop"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_siege_sighted_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_siege_sighted"),
    (try_end),
    (assign, ":var_1", "$g_battle_result"),
    (call_script, "script_encounter_calculate_fit"),
    (assign, "$battle_renown_value", 5),
    (str_store_string, s1, "@As a last defensive effort, you retreat to the main hall of the keep. You and your remaining soldiers will put up a desperate fight here. If you are defeated, there's no other place to fall back to."),
    (str_store_string, s1, "@You've been driven away from the walls. Now the attackers are pouring into the streets. IF you can defeat them, you can perhaps turn the tide and save the day."),
    (try_begin),
        (this_or_next|neg|eq, ":var_1", 1),
        (this_or_next|neg|gt, "$g_friend_fit_for_battle", 0),
        (neg|gt, "$g_enemy_fit_for_battle", 0),
        (jump_to_menu, "$g_siege_final_menu"),
    (else_try),
        (call_script, "script_encounter_calculate_fit"),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (try_begin),
            (eq, "$g_siege_battle_state", 0),
            (eq, ":var_1", 1),
            (assign, "$g_battle_result", 0),
            (jump_to_menu, "$g_siege_final_menu"),
        (else_try),
            (eq, "$g_siege_battle_state", 1),
            (eq, ":var_1", 1),
            (str_store_string, s1, "@You've breached the town walls, but the stubborn defenders continue to resist you in the streets! You'll have to deal with them before you can attack the keep at the heart of the town."),
        (else_try),
            (eq, "$g_siege_battle_state", 2),
            (eq, ":var_1", 1),
            (str_store_string, s1, "@The town centre is yours, but the remaining defenders have retreated to the castle. It must fall before you can complete your victory."),
        (else_try),
            (jump_to_menu, "$g_siege_final_menu"),
        (try_end),
    (else_try),
        (try_begin),
            (eq, "$g_siege_battle_state", 0),
            (eq, ":var_1", 1),
            (assign, "$g_battle_result", 0),
            (jump_to_menu, "$g_siege_final_menu"),
        (else_try),
            (eq, "$g_siege_battle_state", 1),
            (eq, ":var_1", 1),
            (str_store_string, s1, "@The remaining defenders have retreated to the castle as a last defense. You must go in and crush any remaining resistance."),
        (else_try),
            (jump_to_menu, "$g_siege_final_menu"),
        (try_end),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (try_begin),
                (eq, "$g_siege_battle_state", 1),
                (party_get_slot, ":var_0", "$g_encountered_party", slot_town_center),
                (set_jump_mission, "mt_besiege_inner_battle_town_center"),
            (else_try),
                (party_get_slot, ":var_0", "$g_encountered_party", slot_town_castle),
                (set_jump_mission, "mt_besiege_inner_battle_castle"),
            (try_end),
        (else_try),
            (party_get_slot, ":var_0", "$g_encountered_party", slot_town_castle),
            (set_jump_mission, "mt_besiege_inner_battle_castle"),
        (try_end),
        (set_party_battle_mode),
        (jump_to_scene, ":var_0"),
        (val_add, "$g_siege_battle_state", 1),
        (assign, "$g_next_menu", "mnu_castle_besiege_inner_battle"),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

]),

("construct_ladders", 0,
"As the party member with the highest Engineer skill ({reg2}), {reg3?you estimate:{s3} estimates} that it will take {reg4} hours to build enough scaling ladders for the assault.",
"none", 
[
    (call_script, "script_get_max_skill_of_player_party", "skl_engineer"),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (assign, reg2, ":var_0"),
    (store_sub, reg4, 14, ":var_0"),
    (val_mul, reg4, 2),
    (val_div, reg4, 3),
    (try_begin),
        (eq, ":var_1", "trp_player"),
        (assign, reg3, 1),
    (else_try),
        (assign, reg3, 0),
        (str_store_troop_name, s3, ":var_1"),
    (try_end),
],
[
    ("build_ladders_cont", [],
    "Do it.",
    [
        (assign, "$g_siege_method", 1),
        (store_current_hours, ":var_0"),
        (call_script, "script_get_max_skill_of_player_party", "skl_engineer"),
        (store_sub, ":var_1", 14, reg0),
        (val_mul, ":var_1", 2),
        (val_div, ":var_1", 3),
        (store_add, "$g_siege_method_finish_hours", ":var_0", ":var_1"),
        (assign, "$auto_besiege_town", "$current_town"),
        (rest_for_hours_interactive, 96, 5, 1),
        (change_screen_return),
    ], "."),

    ("go_back", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_castle_besiege"),
    ], "."),

]),

("construct_siege_tower", 0,
"As the party member with the highest Engineer skill ({reg2}), {reg3?you estimate:{s3} estimates} that building a siege tower will take {reg4} hours.",
"none", 
[
    (call_script, "script_get_max_skill_of_player_party", "skl_engineer"),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (assign, reg2, ":var_0"),
    (store_sub, reg4, 15, ":var_0"),
    (val_mul, reg4, 6),
    (try_begin),
        (eq, ":var_1", "trp_player"),
        (assign, reg3, 1),
    (else_try),
        (assign, reg3, 0),
        (str_store_troop_name, s3, ":var_1"),
    (try_end),
],
[
    ("build_siege_tower_cont", [],
    "Start building.",
    [
        (assign, "$g_siege_method", 2),
        (store_current_hours, ":var_0"),
        (call_script, "script_get_max_skill_of_player_party", "skl_engineer"),
        (store_sub, ":var_1", 15, reg0),
        (val_mul, ":var_1", 6),
        (store_add, "$g_siege_method_finish_hours", ":var_0", ":var_1"),
        (assign, "$auto_besiege_town", "$current_town"),
        (rest_for_hours_interactive, 240, 5, 1),
        (change_screen_return),
    ], "."),

    ("go_back", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_castle_besiege"),
    ], "."),

]),

("castle_attack_walls_simulate", 4608,
"{s4}^^Your casualties:{s8}^^Enemy casualties were: {s9}",
"none", 
[
    (try_begin),
        (set_background_mesh, "mesh_pic_siege_attack"),
    (try_end),
    (call_script, "script_kt_party_calculate_strength_with_attachments", "p_main_party", 1, 1),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (val_mul, ":var_0", 3),
    (val_div, ":var_0", 4),
    (call_script, "script_kt_party_calculate_strength_with_attachments", "$g_encountered_party", 0, 1),
    (assign, ":var_2", reg0),
    (assign, ":var_3", reg1),
    (val_mul, ":var_2", 13),
    (val_div, ":var_2", 10),
    (val_mul, ":var_2", ":var_1"),
    (val_mul, ":var_0", ":var_3"),
    (val_div, ":var_2", 100),
    (val_div, ":var_0", 100),
    (val_div, ":var_2", 50),
    (val_div, ":var_0", 50),
    (inflict_casualties_to_party_group, "p_main_party", ":var_2", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s8, 0),
    (inflict_casualties_to_party_group, "$g_encountered_party", ":var_0", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s9, 0),
    (assign, "$no_soldiers_left", 0),
    (try_begin),
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (neg|gt, reg0, 0),
        (assign, "$no_soldiers_left", 1),
        (str_store_string, s4, "str_attack_walls_failure"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "$g_encountered_party"),
        (neg|gt, reg0, 0),
        (assign, "$no_soldiers_left", 1),
        (assign, "$g_battle_result", 1),
        (str_store_string, s4, "str_attack_walls_success"),
    (else_try),
        (str_store_string, s4, "str_attack_walls_continue"),
    (try_end),
    (call_script, "script_encounter_calculate_fit"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_castle_besiege"),
    ], "."),

]),

("castle_attack_walls_with_allies_simulate", 4608,
"{s4}^^Your casualties: {s8}^^Allies' casualties: {s9}^^Enemy casualties: {s10}^^Allies remaining: {reg10}^Enemies remaining: {reg11}",
"none", 
[
    (try_begin),
        (set_background_mesh, "mesh_pic_siege_attack"),
    (try_end),
    (call_script, "script_kt_party_calculate_strength", "p_main_party", 1, 1),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (val_mul, ":var_0", 3),
    (val_div, ":var_0", 4),
    (call_script, "script_kt_party_calculate_strength_with_attachments", "$g_ally_party", 0, 1),
    (assign, ":var_2", reg0),
    (assign, ":var_3", reg1),
    (val_mul, ":var_2", 3),
    (val_div, ":var_2", 4),
    (val_max, ":var_2", 1),
    (call_script, "script_kt_party_calculate_strength", "p_collective_enemy", 0, 1),
    (assign, ":var_4", reg0),
    (assign, ":var_5", reg1),
    (val_mul, ":var_4", 13),
    (val_div, ":var_4", 10),
    (store_add, ":var_6", ":var_0", ":var_2"),
    (store_mul, ":var_7", ":var_1", ":var_4"),
    (store_mul, ":var_8", ":var_3", ":var_4"),
    (val_mul, ":var_7", ":var_0"),
    (val_mul, ":var_8", ":var_2"),
    (val_div, ":var_7", ":var_6"),
    (val_div, ":var_8", ":var_6"),
    (val_div, ":var_7", 100),
    (val_div, ":var_8", 100),
    (store_mul, ":var_9", ":var_6", ":var_5"),
    (val_div, ":var_9", 100),
    (val_div, ":var_7", 50),
    (val_div, ":var_8", 50),
    (val_div, ":var_9", 50),
    (inflict_casualties_to_party_group, "p_main_party", ":var_7", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s8, 0),
    (inflict_casualties_to_party_group, "$g_enemy_party", ":var_9", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s10, 0),
    (call_script, "script_collect_friendly_parties"),
    (inflict_casualties_to_party_group, "$g_ally_party", ":var_8", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s9, 0),
    (party_collect_attachments_to_party, "$g_enemy_party", "p_collective_enemy"),
    (assign, "$no_soldiers_left", 0),
    (try_begin),
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (neg|gt, reg0, 0),
        (assign, "$no_soldiers_left", 1),
        (str_store_string, s4, "str_attack_walls_failure"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
        (neg|gt, reg0, 0),
        (assign, "$no_soldiers_left", 1),
        (assign, "$g_battle_result", 1),
        (str_store_string, s4, "str_attack_walls_success"),
    (else_try),
        (str_store_string, s4, "str_attack_walls_continue"),
    (try_end),
    (call_script, "script_encounter_calculate_fit"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_besiegers_camp_with_allies"),
    ], "."),

]),

("castle_taken_by_friends", 0,
"Nothing to see here.",
"none", 
[
    (party_clear, "$g_encountered_party"),
    (party_stack_get_troop_id, ":var_0", "$g_encountered_party_2", 0),
    (party_set_slot, "$g_encountered_party", slot_center_last_taken_by_troop, ":var_0"),
    (store_troop_faction, ":var_1", ":var_0"),
    (call_script, "script_change_center_prosperity", "$g_encountered_party", -5),
    (try_begin),
        (assign, ":var_2", 20),
        (is_between, "$g_encountered_party", "p_town_1", "p_castle_1"),
        (assign, ":var_2", 40),
    (try_end),
    (try_begin),
        (neg|eq, ":var_1", "$g_encountered_party_faction"),
        (call_script, "script_faction_inflict_war_damage_on_faction", ":var_1", "$g_encountered_party_faction", ":var_2"),
    (try_end),
    (call_script, "script_give_center_to_faction", "$g_encountered_party", ":var_1"),
    (call_script, "script_add_log_entry", 18, "trp_player", "$g_encountered_party", 0, "$g_encountered_party_faction"),
    (change_screen_return),
],
[
]),

("castle_taken", 512,
"{s3} has fallen to your troops, and you now have full control of the {reg2?town:castle}.{reg1? You may station troops here to defend it against enemies who may try to recapture it. Also, you should select now whether you will hold the {reg2?town:castle} yourself or give it to a faithful vassal...:}",
"none", 
[
    (party_clear, "$g_encountered_party"),
    (try_begin),
        (eq, "$players_kingdom", "fac_player_supporters_faction"),
        (party_get_slot, ":var_0", "$g_encountered_party", slot_town_lord),
        (neg|eq, ":var_0", "trp_player"),
        (try_for_range, ":var_1", 0, 4),
            (call_script, "script_cf_reinforce_party", "$g_encountered_party"),
        (try_end),
    (try_end),
    (call_script, "script_lift_siege", "$g_encountered_party", 0),
    (assign, "$g_player_besiege_town", -1),
    (party_set_slot, "$g_encountered_party", slot_center_last_taken_by_troop, "trp_player"),
    (call_script, "script_generate_refugees", "$g_encountered_party", 1),
    (call_script, "script_change_center_prosperity", "$g_encountered_party", -5),
    (call_script, "script_change_troop_renown", "trp_player", 5),
    (assign, ":var_2", 20),
    (try_begin),
        (is_between, "$g_encountered_party", "p_town_1", "p_castle_1"),
        (assign, ":var_2", 40),
    (try_end),
    (call_script, "script_faction_inflict_war_damage_on_faction", "$players_kingdom", "$g_encountered_party_faction", ":var_2"),
    (try_begin),
        (is_between, "$players_kingdom", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (neg|eq, "$players_kingdom", "fac_player_supporters_faction"),
        (call_script, "script_give_center_to_faction", "$g_encountered_party", "$players_kingdom"),
        (call_script, "script_order_best_besieger_party_to_guard_center", "$g_encountered_party", "$players_kingdom"),
        (jump_to_menu, "mnu_castle_taken_2"),
    (else_try),
        (call_script, "script_give_center_to_faction", "$g_encountered_party", "fac_player_supporters_faction"),
        (call_script, "script_order_best_besieger_party_to_guard_center", "$g_encountered_party", "fac_player_supporters_faction"),
        (str_store_party_name, s3, "$g_encountered_party"),
        (assign, reg1, 0),
        (try_begin),
            (faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
            (assign, reg1, 1),
        (try_end),
    (try_end),
    (assign, reg2, 0),
    (try_begin),
        (is_between, "$g_encountered_party", "p_town_1", "p_castle_1"),
        (assign, reg2, 1),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$auto_enter_town", "$g_encountered_party"),
        (change_screen_return),
    ], "."),

]),

("castle_taken_2", 512,
"{s3} has fallen to your troops, and you now have full control of the castle. It is time to send word to {s9} about your victory. {s5}",
"none", 
[
    (str_store_party_name, s3, "$g_encountered_party"),
    (str_clear, s5),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s9, ":var_0"),
    (try_begin),
        (eq, "$player_has_homage", 0),
        (assign, reg8, 0),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_ignore_player_until),
            (assign, reg8, 1),
        (try_end),
        (call_script, "script_gender_to_reg63"),
        (str_store_string, s5, "@However, since you are not a sworn {reg63?man:follower} of {s9}, there is no chance he would recognize you as the {reg63?lord:lady} of this {reg8?town:castle}."),
    (try_end),
],
[
    ("castle_taken_claim", 
    [
        (eq, "$player_has_homage", 1),
    ],
    "Request that {s3} be awarded to you.",
    [
        (party_set_slot, "$g_encountered_party", slot_center_last_taken_by_troop, "trp_player"),
        (assign, "$g_castle_requested_by_player", "$current_town"),
        (assign, "$g_castle_requested_for_troop", "trp_player"),
        (assign, "$auto_enter_town", "$g_encountered_party"),
        (change_screen_return),
    ], "."),

    ("castle_taken_claim_2", 
    [
        (troop_get_slot, ":var_0", "trp_player", slot_troop_spouse),
        (is_between, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (store_troop_faction, ":var_1", ":var_0"),
        (eq, ":var_1", "$players_kingdom"),
        (call_script, "script_gender_to_reg63"),
    ],
    "Request that {s3} be awarded to your {reg63?wife:husband}.",
    [
        (party_set_slot, "$g_encountered_party", slot_center_last_taken_by_troop, "trp_player"),
        (assign, "$g_castle_requested_by_player", "$current_town"),
        (troop_get_slot, ":var_0", "trp_player", slot_troop_spouse),
        (assign, "$g_castle_requested_for_troop", ":var_0"),
        (assign, "$auto_enter_town", "$g_encountered_party"),
        (change_screen_return),
    ], "."),

    ("castle_taken_no_claim", [],
    "Ask no rewards.",
    [
        (party_set_slot, "$g_encountered_party", slot_center_last_taken_by_troop, -1),
        (assign, "$auto_enter_town", "$g_encountered_party"),
        (change_screen_return),
    ], "."),

]),

("requested_castle_granted_to_player", 4096,
"You receive a message from your liege, {s3}.^^ {reg4?She:He} has decided to grant {s2}{reg3? and the nearby village of {s4}:} to you, with all due incomes and titles, to hold in {reg4?her:his} name for as long as you maintain your oath of homage..",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s3, ":var_0"),
    (str_store_party_name, s2, "$g_center_to_give_to_player"),
    (try_begin),
        (party_slot_eq, "$g_center_to_give_to_player", slot_party_type, 2),
        (assign, reg3, 1),
        (try_for_range, ":var_1", "p_village_1", "p_salt_mine"),
            (party_slot_eq, ":var_1", slot_village_bound_center, "$g_center_to_give_to_player"),
            (str_store_party_name, s4, ":var_1"),
        (try_end),
    (else_try),
        (assign, reg3, 0),
    (try_end),
    (troop_get_type, reg4, ":var_0"),
],
[
    ("continue", [],
    "Continue.",
    [
        (call_script, "script_give_center_to_lord", "$g_center_to_give_to_player", "trp_player", 0),
        (jump_to_menu, "mnu_give_center_to_player_2"),
    ], "."),

]),

("requested_castle_granted_to_player_husband", 4096,
"You receive a message from your liege, {s3}.^^ {reg4?She:He} has decided to grant {s2}{reg3? and the nearby village of {s4}:} to your husband, {s7}.",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s3, ":var_0"),
    (str_store_party_name, s2, "$g_center_to_give_to_player"),
    (try_begin),
        (party_slot_eq, "$g_center_to_give_to_player", slot_party_type, 2),
        (assign, reg3, 1),
        (try_for_range, ":var_1", "p_village_1", "p_salt_mine"),
            (party_slot_eq, ":var_1", slot_village_bound_center, "$g_center_to_give_to_player"),
            (str_store_party_name, s4, ":var_1"),
        (try_end),
    (else_try),
        (assign, reg3, 0),
    (try_end),
    (troop_get_type, reg4, ":var_0"),
    (troop_get_slot, ":var_2", "trp_player", slot_troop_spouse),
    (str_store_troop_name, s11, ":var_2"),
    (str_store_string, s7, "str_to_your_husband_s11"),
],
[
    ("continue", [],
    "Continue.",
    [
        (troop_get_slot, ":var_0", "trp_player", slot_troop_spouse),
        (call_script, "script_give_center_to_lord", "$g_center_to_give_to_player", ":var_0", 0),
    ], "."),

]),

("requested_castle_granted_to_another", 4096,
"You receive a message from your monarch, {s3}.^^ 'I was most pleased to hear of your valiant efforts in the capture of {s2}. Your victory has gladdened all our hearts. You also requested me to give you ownership of the castle, but that is a favour which I fear I cannot grant, as you already hold significant estates in my realm. Instead I have sent you {reg6} denars to cover the expenses of your campaign, but {s2} I give to {s5}.' ",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s3, ":var_0"),
    (str_store_party_name, s2, "$g_center_to_give_to_player"),
    (party_get_slot, ":var_1", "$g_center_to_give_to_player", slot_town_lord),
    (str_store_troop_name, s5, ":var_1"),
    (assign, reg6, 900),
    (assign, "$g_castle_requested_by_player", -1),
    (assign, "$g_castle_requested_for_troop", -1),
],
[
    ("accept_decision", [],
    "Accept the decision.",
    [
        (call_script, "script_troop_add_gold", "trp_player", reg6),
        (change_screen_return),
    ], "."),

    ("leave_faction", [],
    "You have been wronged! Renounce your oath to your liege! ",
    [
        (jump_to_menu, "mnu_leave_faction"),
        (call_script, "script_troop_add_gold", "trp_player", reg6),
    ], "."),

]),

("requested_castle_granted_to_another_female", 4096,
"You receive a message from your monarch, {s3}.^^ 'I was most pleased to hear of your valiant efforts in the capture of {s2}. Your victory has gladdened all our hearts. You also requested me to give ownership of the castle to your husband, but that is a favour which I fear I cannot grant, as he already holds significant estates in my realm. Instead I have sent you {reg6} denars to cover the expenses of your campaign, but {s2} I give to {s5}.' ",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s3, ":var_0"),
    (str_store_party_name, s2, "$g_center_to_give_to_player"),
    (party_get_slot, ":var_1", "$g_center_to_give_to_player", slot_town_lord),
    (str_store_troop_name, s5, ":var_1"),
    (assign, reg6, 900),
    (assign, "$g_castle_requested_by_player", -1),
    (assign, "$g_castle_requested_for_troop", -1),
],
[
    ("accept_decision", [],
    "Accept the decision.",
    [
        (call_script, "script_troop_add_gold", "trp_player", reg6),
        (change_screen_return),
    ], "."),

]),

("leave_faction", 0,
"Renouncing your oath is a grave act. Your lord may condemn you and confiscate your lands and holdings. However, if you return them of your own free will, he may let the betrayal go without a fight.",
"none", [],
[
    ("leave_faction_give_back", [],
    "Renounce your oath and give up your holdings.",
    [
        (call_script, "script_player_leave_faction", 1),
        (change_screen_return),
    ], "."),

    ("leave_faction_hold", 
    [
        (str_store_party_name, s2, "$g_center_to_give_to_player"),
    ],
    "Renounce your oath and rule your lands, including {s2}, in your own name.",
    [
        (call_script, "script_give_center_to_lord", "$g_center_to_give_to_player", "trp_player", 0),
        (call_script, "script_player_leave_faction", 0),
        (call_script, "script_activate_player_faction", "trp_player"),
        (change_screen_return),
    ], "."),

    ("leave_faction_cancel", [],
    "Remain loyal and accept the decision.",
    [
        (change_screen_return),
    ], "."),

]),

("give_center_to_player", 4096,
"Your lord offers to extend your fiefs! {s1} sends word that he is willing to grant {s2} to you in payment for your loyal service, adding it to your holdings. What is your answer?",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (store_faction_of_party, ":var_0", "$g_center_to_give_to_player"),
    (faction_get_slot, ":var_1", ":var_0", slot_faction_leader),
    (str_store_troop_name, s1, ":var_1"),
    (str_store_party_name, s2, "$g_center_to_give_to_player"),
],
[
    ("give_center_to_player_accept", [],
    "Accept the offer.",
    [
        (call_script, "script_give_center_to_lord", "$g_center_to_give_to_player", "trp_player", 0),
        (jump_to_menu, "mnu_give_center_to_player_2"),
    ], "."),

    ("give_center_to_player_reject", [],
    "Reject. You have no interest in holding {s2}.",
    [
        (party_set_slot, "$g_center_to_give_to_player", slot_town_lord, -3),
        (change_screen_return),
    ], "."),

]),

("give_center_to_player_2", 0,
"With a brief ceremony, you are officially confirmed as the new lord of {s2}{reg3? and its bound village {s4}:}. {reg3?They:It} will make a fine part of your fiefdom. You can now claim the rents and revenues from your personal estates there, draft soldiers from the populace, and manage the lands as you see fit. However, you are also expected to defend your fief and your people from harm, as well as maintaining the rule of law and order.",
"none", 
[
    (str_store_party_name, s2, "$g_center_to_give_to_player"),
    (assign, reg3, 0),
    (try_begin),
        (party_slot_eq, "$g_center_to_give_to_player", slot_party_type, 2),
        (try_for_range, ":var_0", "p_village_1", "p_salt_mine"),
            (party_slot_eq, ":var_0", slot_village_bound_center, "$g_center_to_give_to_player"),
            (str_store_party_name, s4, ":var_0"),
            (assign, reg3, 1),
        (try_end),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("oath_fulfilled", 0,
"You had a contract with {s1} to serve him for a certain duration. Your contract has now expired. What will you do?",
"none", 
[
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s1, ":var_0"),
],
[
    ("renew_oath", 
    [
        (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
        (str_store_troop_name, s1, ":var_0"),
    ],
    "Renew your contract with {s1} for another month.",
    [
        (store_current_day, ":var_0"),
        (store_add, "$mercenary_service_next_renew_day", ":var_0", 30),
        (change_screen_return),
    ], "."),

    ("dont_renew_oath", [],
    "Become free of your bond.",
    [
        (call_script, "script_player_leave_faction", 1),
        (change_screen_return),
    ], "."),

]),

("siege_started_defender", 256,
"{s1} is launching an assault against the walls of {s2}. You have {reg10} troops fit for battle against the enemy's {reg11}. You decide to...",
"none", 
[
    (select_enemy, 1),
    (assign, "$g_enemy_party", "$g_encountered_party_2"),
    (assign, "$g_ally_party", "$g_encountered_party"),
    (str_store_party_name, s1, "$g_enemy_party"),
    (str_store_party_name, s2, "$g_ally_party"),
    (call_script, "script_encounter_calculate_fit"),
    (try_begin),
        (eq, "$g_siege_first_encounter", 1),
        (call_script, "script_let_nearby_parties_join_current_battle", 0, 1),
        (call_script, "script_encounter_init_variables"),
    (try_end),
    (try_begin),
        (eq, "$g_siege_first_encounter", 0),
        (try_begin),
            (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
            (assign, ":var_0", reg0),
            (call_script, "script_party_count_members_with_full_health", "p_collective_friends"),
            (assign, ":var_1", reg0),
            (assign, ":var_2", 0),
            (try_begin),
                (eq, "$g_battle_result", 1),
                (eq, ":var_0", 0),
                (assign, ":var_2", 1),
            (else_try),
                (eq, "$g_engaged_enemy", 1),
                (neg|gt, "$g_enemy_fit_for_battle", 0),
                (ge, "$g_friend_fit_for_battle", 1),
                (assign, ":var_2", 1),
            (try_end),
            (this_or_next|eq, ":var_2", 1),
            (eq, "$g_enemy_surrenders", 1),
            (assign, "$g_next_menu", -1),
            (jump_to_menu, "mnu_total_victory"),
        (else_try),
            (assign, ":var_3", 0),
            (try_begin),
                (this_or_next|eq, "$g_battle_result", -1),
                (troop_is_wounded, "trp_player"),
                (eq, ":var_1", 0),
                (assign, ":var_3", 1),
            (try_end),
            (this_or_next|eq, ":var_3", 1),
            (eq, "$g_player_surrenders", 1),
            (assign, "$g_next_menu", "mnu_captivity_start_under_siege_defeat"),
            (jump_to_menu, "mnu_total_defeat"),
        (else_try),
            (assign, ":var_4", 0),
            (try_begin),
                (eq, "$g_battle_result", 1),
                (assign, ":var_4", 1),
            (else_try),
                (eq, "$g_battle_result", 0),
                (store_div, ":var_5", "$g_enemy_fit_for_battle", 3),
                (neg|ge, ":var_5", "$g_friend_fit_for_battle"),
                (assign, ":var_4", 1),
            (else_try),
                (store_random_in_range, ":var_6", 0, 100),
                (store_mul, ":var_7", ":var_1", 13),
                (val_div, ":var_7", 10),
                (ge, ":var_7", ":var_0"),
                (neg|ge, ":var_6", 10),
                (neg|eq, "$new_encounter", 1),
                (assign, ":var_4", 1),
            (try_end),
            (try_begin),
                (eq, ":var_4", 1),
                (party_get_slot, ":var_8", "$g_encountered_party", slot_center_siege_hardness),
                (val_add, ":var_8", 100),
                (party_set_slot, "$g_encountered_party", slot_center_siege_hardness, ":var_8"),
                (party_set_slot, "$g_enemy_party", slot_party_retreat_flag, 1),
                (try_for_range, ":var_9", "trp_npc_adonja", "trp_knight_1_1_wife"),
                    (troop_slot_eq, ":var_9", slot_troop_occupation, 2),
                    (neg|troop_slot_ge, ":var_9", slot_troop_prisoner_of_party, 0),
                    (troop_get_slot, ":var_10", ":var_9", slot_troop_leaded_party),
                    (gt, ":var_10", 0),
                    (party_slot_eq, ":var_10", slot_party_ai_state, 1),
                    (party_slot_eq, ":var_10", slot_party_ai_object, "$g_encountered_party"),
                    (party_slot_eq, ":var_10", slot_party_ai_substate, 1),
                    (call_script, "script_party_set_ai_state", ":var_10", -1, -1),
                    (call_script, "script_party_set_ai_state", ":var_10", 1, "$g_encountered_party"),
                (try_end),
                (try_begin),
                    (store_faction_of_party, ":var_11", "$g_enemy_party"),
                    (neg|is_between, ":var_11", "fac_player_supporters_faction", "fac_kingdoms_end"),
                    (party_set_ai_behavior, "$g_enemy_party", 2),
                    (party_set_ai_initiative, "$g_enemy_party", 100),
                    (display_message, "@The enemy has been forced to retreat and abandon the surprise assault."),
                (else_try),
                    (display_message, "@The enemy has been forced to retreat. The assault is over, but the siege continues."),
                (try_end),
                (assign, "$g_battle_simulation_cancel_for_party", "$g_encountered_party"),
                (leave_encounter),
                (change_screen_return),
                (assign, "$g_battle_simulation_auto_enter_town_after_battle", "$g_encountered_party"),
            (try_end),
        (try_end),
    (try_end),
    (assign, "$g_siege_first_encounter", 0),
    (assign, "$new_encounter", 0),
],
[
    ("change_commander", 
    [
        (str_store_troop_name, s7, "$g_player_troop"),
        (set_player_troop, "$g_player_troop"),
    ],
    "Change commander.(Current commander: {s7})",
    [
        (start_presentation, "prsnt_change_commander"),
    ], "."),

    ("siege_defender_join_battle", 
    [
        (neg|troop_is_wounded, "trp_player"),
    ],
    "Join the battle.",
    [
        (party_set_next_battle_simulation_time, "$g_encountered_party", -1),
        (assign, "$g_battle_result", 0),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (party_get_slot, ":var_0", "$g_encountered_party", slot_town_walls),
        (else_try),
            (party_get_slot, ":var_0", "$g_encountered_party", slot_town_center),
        (try_end),
        (call_script, "script_calculate_renown_value"),
        (call_script, "script_calculate_battle_advantage"),
        (val_mul, reg0, 2),
        (val_div, reg0, 3),
        (set_battle_advantage, reg0),
        (set_party_battle_mode),
        (try_begin),
            (party_slot_eq, "$current_town", slot_center_siege_with_belfry, 1),
            (set_jump_mission, "mt_castle_attack_walls_belfry"),
        (else_try),
            (set_jump_mission, "mt_castle_attack_walls_ladder"),
        (try_end),
        (jump_to_scene, ":var_0"),
        (assign, "$g_next_menu", "mnu_siege_started_defender"),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

    ("siege_defender_troops_join_battle", 
    [
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (this_or_next|troop_is_wounded, "trp_player"),
        (ge, reg0, 3),
    ],
    "Order your men to join the battle without you.",
    [
        (party_set_next_battle_simulation_time, "$g_encountered_party", -1),
        (select_enemy, 1),
        (assign, "$g_enemy_party", "$g_encountered_party_2"),
        (assign, "$g_ally_party", "$g_encountered_party"),
        (assign, "$g_siege_join", 1),
        (jump_to_menu, "mnu_siege_join_defense"),
    ], "."),

]),

("siege_join_defense", 512,
"{s4}^^Your casualties: {s8}^^Allies' casualties: {s9}^^Enemy casualties: {s10}^^Allies remaining: {reg10}^Enemies remaining: {reg11}",
"none", 
[
    (try_begin),
        (eq, "$g_siege_join", 1),
        (call_script, "script_kt_party_calculate_strength", "p_main_party", 1, 1),
        (assign, ":var_0", reg0),
        (assign, ":var_1", reg1),
        (val_mul, ":var_0", 13),
        (val_div, ":var_0", 10),
    (else_try),
        (assign, ":var_0", 0),
        (assign, ":var_1", 1),
    (try_end),
    (call_script, "script_kt_party_calculate_strength_with_attachments", "$g_ally_party", 0, 1),
    (assign, ":var_2", reg0),
    (assign, ":var_3", reg1),
    (val_mul, ":var_2", 13),
    (val_div, ":var_2", 10),
    (call_script, "script_kt_party_calculate_strength", "p_collective_enemy", 0, 1),
    (assign, ":var_4", reg0),
    (assign, ":var_5", reg1),
    (val_mul, ":var_4", 3),
    (val_div, ":var_4", 4),
    (store_add, ":var_6", ":var_0", ":var_2"),
    (store_mul, ":var_7", ":var_1", ":var_4"),
    (store_mul, ":var_8", ":var_3", ":var_4"),
    (val_mul, ":var_7", ":var_0"),
    (val_mul, ":var_8", ":var_2"),
    (val_div, ":var_7", ":var_6"),
    (val_div, ":var_8", ":var_6"),
    (val_div, ":var_7", 100),
    (val_div, ":var_8", 100),
    (store_mul, ":var_9", ":var_6", ":var_5"),
    (val_div, ":var_9", 100),
    (val_div, ":var_7", 50),
    (val_div, ":var_8", 50),
    (val_div, ":var_9", 50),
    (inflict_casualties_to_party_group, "p_main_party", ":var_7", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s8, 0),
    (inflict_casualties_to_party_group, "$g_ally_party", ":var_8", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s9, 0),
    (party_collect_attachments_to_party, "$g_ally_party", "p_collective_ally"),
    (inflict_casualties_to_party_group, "$g_enemy_party", ":var_9", "p_temp_casualties"),
    (call_script, "script_print_casualties_to_s0", "p_temp_casualties", 0),
    (str_store_string_reg, s10, 0),
    (party_collect_attachments_to_party, "$g_enemy_party", "p_collective_enemy"),
    (try_begin),
        (call_script, "script_party_count_members_with_full_health", "p_main_party"),
        (neg|gt, reg0, 0),
        (str_store_string, s4, "str_siege_defender_order_attack_failure"),
    (else_try),
        (call_script, "script_party_count_members_with_full_health", "p_collective_enemy"),
        (neg|gt, reg0, 0),
        (assign, "$g_battle_result", 1),
        (str_store_string, s4, "str_siege_defender_order_attack_success"),
    (else_try),
        (str_store_string, s4, "str_siege_defender_order_attack_continue"),
    (try_end),
    (call_script, "script_encounter_calculate_fit"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_siege_started_defender"),
    ], "."),

]),

("enter_your_own_castle", 0,
"{s10}",
"none", 
[
    (call_script, "script_gender_to_reg63"),
    (try_begin),
        (neg|is_between, "$players_kingdom", "fac_kingdom_1", "fac_kingdoms_end"),
        (faction_get_slot, ":var_0", "fac_player_supporters_faction", slot_faction_leader),
        (eq, ":var_0", "trp_player"),
        (str_store_string, s10, "@As you approach, you are spotted by the castle guards, who welcome you and open the gates for their {reg63?king:queen}."),
    (else_try),
        (str_store_string, s10, "@As you approach, you are spotted by the castle guards, who welcome you and open the gates for their {reg63?lord:lady}."),
    (try_end),
    (str_store_party_name, s2, "$current_town"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("village", 256,
"{s10} {s12}^{s11}^{s6}{s7}",
"none", 
[
    (call_script, "script_detect_load_restore_custom_troops"),
    (assign, "$current_town", "$g_encountered_party"),
    (call_script, "script_update_center_recon_notes", "$current_town"),
    (assign, "$g_defending_against_siege", 0),
    (assign, "$g_battle_result", 0),
    (assign, "$qst_collect_taxes_currently_collecting", 0),
    (assign, "$qst_train_peasants_against_bandits_currently_training", 0),
    (call_script, "script_music_set_situation_with_culture", 67108864),
    (try_begin),
        (gt, "$auto_enter_menu_in_center", 0),
        (jump_to_menu, "$auto_enter_menu_in_center"),
        (assign, "$auto_enter_menu_in_center", 0),
    (try_end),
    (try_begin),
        (neg|eq, "$g_player_raiding_village", "$current_town"),
        (assign, "$g_player_raiding_village", 0),
    (else_try),
        (jump_to_menu, "mnu_village_loot_continue"),
    (try_end),
    (try_begin),
        (eq, "$g_town_visit_after_rest", 1),
        (assign, "$g_town_visit_after_rest", 0),
    (try_end),
    (str_store_party_name, s2, "$current_town"),
    (party_get_slot, ":var_0", "$current_town", slot_town_lord),
    (store_faction_of_party, ":var_1", "$current_town"),
    (str_store_faction_name, s9, ":var_1"),
    (try_begin),
        (ge, ":var_0", 0),
        (str_store_troop_name, s8, ":var_0"),
        (str_store_string, s7, "@{s8} of the {s9}"),
    (try_end),
    (str_clear, s10),
    (str_clear, s12),
    (try_begin),
        (neg|party_slot_eq, "$current_town", slot_village_state, 2),
        (str_store_string, s60, 2),
        (party_get_slot, ":var_2", "$current_town", slot_town_prosperity),
        (try_begin),
            (eq, "$cheat_mode", 1),
            (assign, reg4, ":var_2"),
            (display_message, "@{!}Prosperity: {reg4}"),
        (try_end),
        (try_begin),
            (neg|gt, ":var_2", 3),
            (assign, ":var_3", 0),
        (else_try),
            (neg|gt, ":var_2", 9),
            (assign, ":var_3", 1),
        (else_try),
            (neg|gt, ":var_2", 24),
            (assign, ":var_3", 2),
        (else_try),
            (neg|gt, ":var_2", 45),
            (assign, ":var_3", 3),
        (else_try),
            (neg|gt, ":var_2", 75),
            (assign, ":var_3", 4),
        (else_try),
            (neg|gt, ":var_2", 117),
            (assign, ":var_3", 5),
        (else_try),
            (neg|gt, ":var_2", 183),
            (assign, ":var_3", 6),
        (else_try),
            (neg|gt, ":var_2", 225),
            (assign, ":var_3", 7),
        (else_try),
            (neg|gt, ":var_2", 255),
            (assign, ":var_3", 8),
        (else_try),
            (neg|gt, ":var_2", 276),
            (assign, ":var_3", 19),
        (else_try),
            (neg|gt, ":var_2", 291),
            (assign, ":var_3", 10),
        (else_try),
            (neg|gt, ":var_2", 297),
            (assign, ":var_3", 11),
        (else_try),
            (gt, ":var_2", 297),
            (assign, ":var_3", 12),
        (try_end),
        (store_add, ":var_4", "str_village_prosperity_0", ":var_3"),
        (str_store_string, s10, ":var_4"),
        (store_div, ":var_4", ":var_2", 60),
        (val_min, ":var_4", 4),
        (try_begin),
            (val_add, ":var_4", "str_village_alt_prosperity_0"),
        (try_end),
        (str_store_string, s12, ":var_4"),
    (try_end),
    (str_clear, s11),
    (try_begin),
        (party_slot_eq, "$current_town", slot_village_state, 2),
    (else_try),
        (eq, ":var_0", "trp_player"),
        (str_store_string, s11, "@ This village and the surrounding lands belong to you."),
    (else_try),
        (ge, ":var_0", 0),
        (str_store_string, s11, "@ You remember that this village and the surrounding lands belong to {s7}."),
    (else_try),
        (str_store_string, s11, "@ These lands belong to no one."),
    (try_end),
    (str_clear, s7),
    (try_begin),
        (neg|party_slot_eq, "$current_town", slot_village_state, 2),
        (party_get_slot, ":var_5", "$current_town", slot_center_player_relation),
        (call_script, "script_describe_center_relation_to_s3", ":var_5"),
        (assign, reg9, ":var_5"),
        (str_store_string, s7, "@{!} {s3} ({reg9})."),
    (try_end),
    (str_clear, s6),
    (try_begin),
        (party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (party_get_slot, ":var_6", "$current_town", slot_village_infested_by_bandits),
        (store_character_level, ":var_7", "trp_player"),
        (store_add, "$qst_eliminate_bandits_infesting_village_num_bandits", ":var_7", 10),
        (val_mul, "$qst_eliminate_bandits_infesting_village_num_bandits", 12),
        (val_div, "$qst_eliminate_bandits_infesting_village_num_bandits", 10),
        (store_random_in_range, "$qst_eliminate_bandits_infesting_village_num_villagers", 25, 30),
        (assign, reg8, "$qst_eliminate_bandits_infesting_village_num_bandits"),
        (str_store_troop_name_by_count, s35, ":var_6", "$qst_eliminate_bandits_infesting_village_num_bandits"),
        (str_store_string, s6, "@ The village is infested by {reg8} {s35}."),
        (assign, "$g_enemy_party", -1),
        (assign, "$g_ally_party", -1),
        (try_begin),
            (eq, ":var_6", "trp_forest_bandit"),
            (set_background_mesh, "mesh_pic_forest_bandits"),
        (else_try),
            (eq, ":var_6", "trp_steppe_bandit"),
            (set_background_mesh, "mesh_pic_steppe_bandits"),
        (else_try),
            (eq, ":var_6", "trp_mountain_bandit"),
            (set_background_mesh, "mesh_pic_mountain_bandits"),
        (else_try),
            (eq, ":var_6", "trp_sea_raider"),
            (set_background_mesh, "mesh_pic_sea_raiders"),
        (else_try),
            (set_background_mesh, "mesh_pic_bandits"),
        (try_end),
    (else_try),
        (party_slot_eq, "$current_town", slot_village_state, 2),
        (str_store_string, s6, "@ The village has been looted. A handful of souls scatter as you pass through the burnt out houses."),
        (try_begin),
            (neg|eq, "$g_player_raid_complete", 1),
            (play_track, "track_empty_village_lic", 1),
        (try_end),
        (set_background_mesh, "mesh_pic_looted_village"),
    (else_try),
        (party_slot_eq, "$current_town", slot_village_state, 1),
        (str_store_string, s6, "@ The village is being raided."),
    (else_try),
        (party_get_current_terrain, ":var_8", "$current_town"),
        (try_begin),
            (this_or_next|eq, ":var_8", 2),
            (this_or_next|eq, ":var_8", 10),
            (this_or_next|eq, ":var_8", 5),
            (eq, ":var_8", 13),
            (set_background_mesh, "mesh_pic_village_s"),
        (else_try),
            (this_or_next|eq, ":var_8", 4),
            (eq, ":var_8", 12),
            (set_background_mesh, "mesh_pic_village_w"),
        (else_try),
            (set_background_mesh, "mesh_pic_village_p"),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$g_player_raid_complete", 1),
        (assign, "$g_player_raid_complete", 0),
        (jump_to_menu, "mnu_village_loot_complete"),
    (else_try),
        (party_get_slot, ":var_9", "$current_town", slot_village_raided_by),
        (gt, ":var_9", 0),
    (try_end),
    (try_begin),
        (eq, "$g_leave_town", 1),
        (assign, "$g_leave_town", 0),
        (change_screen_return),
    (try_end),
    (try_begin),
        (store_time_of_day, ":var_10"),
        (ge, ":var_10", 5),
        (neg|ge, ":var_10", 21),
        (assign, "$town_nighttime", 0),
    (else_try),
        (assign, "$town_nighttime", 1),
    (try_end),
],
[
    ("village_manage", 
    [
        (neg|party_slot_eq, "$current_town", slot_village_state, 2),
        (neg|party_slot_eq, "$current_town", slot_village_state, 1),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
    ],
    "Manage this village.",
    [
        (assign, "$g_next_menu", "mnu_village"),
        (jump_to_menu, "mnu_center_manage"),
    ], "."),

    ("village_train_steward", 
    [
        (party_slot_eq, "$current_town", 295, 1),
        (neg|party_slot_eq, "$current_town", slot_village_state, 2),
        (neg|party_slot_eq, "$current_town", slot_village_state, 1),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
    ],
    "Train your village steward.",
    [
        (assign, "$g_next_menu", "mnu_village"),
        (jump_to_menu, "mnu_steward_training"),
    ], "."),

    ("village_elder_talk", 
    [
        (neg|party_slot_eq, "$current_town", slot_village_state, 2),
        (neg|party_slot_eq, "$current_town", slot_village_state, 1),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
    ],
    "Speak with the Village Elder.",
    [
        (try_begin),
            (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (party_get_slot, ":var_1", "$current_town", slot_town_elder),
            (set_visitor, 11, ":var_1"),
            (call_script, "script_init_town_walkers"),
            (try_begin),
                (check_quest_active, "qst_hunt_down_fugitive"),
                (neg|is_currently_night),
                (quest_slot_eq, "qst_hunt_down_fugitive", 1, "$current_town"),
                (neg|check_quest_succeeded, "qst_hunt_down_fugitive"),
                (neg|check_quest_failed, "qst_hunt_down_fugitive"),
                (set_visitor, 45, "trp_fugitive"),
            (try_end),
            (set_jump_mission, "mt_village_center"),
            (jump_to_scene, ":var_0"),
            (change_screen_map_conversation, ":var_1"),
        (try_end),
    ], "Door to the village center."),

    ("recruit_volunteers", 
    [
        (call_script, "script_cf_village_recruit_volunteers_cond"),
    ],
    "Recruit Volunteers.",
    [
        (try_begin),
            (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
            (jump_to_menu, "mnu_recruit_volunteers"),
        (try_end),
    ], "."),

    ("village_center", 
    [
        (neg|party_slot_eq, "$current_town", slot_village_state, 2),
        (neg|party_slot_eq, "$current_town", slot_village_state, 1),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
    ],
    "Go to the village center.",
    [
        (try_begin),
            (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (party_get_slot, ":var_1", "$current_town", slot_town_elder),
            (set_visitor, 11, ":var_1"),
            (call_script, "script_init_town_walkers"),
            (try_begin),
                (check_quest_active, "qst_hunt_down_fugitive"),
                (neg|is_currently_night),
                (quest_slot_eq, "qst_hunt_down_fugitive", 1, "$current_town"),
                (neg|check_quest_succeeded, "qst_hunt_down_fugitive"),
                (neg|check_quest_failed, "qst_hunt_down_fugitive"),
                (set_visitor, 45, "trp_fugitive"),
            (try_end),
            (set_jump_mission, "mt_village_center"),
            (jump_to_scene, ":var_0"),
            (change_screen_mission),
        (try_end),
    ], "Door to the village center."),

    ("village_buy_food", 
    [
        (party_slot_eq, "$current_town", slot_village_state, 0),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
    ],
    "Buy supplies from the peasants.",
    [
        (try_begin),
            (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
            (party_get_slot, ":var_0", "$current_town", slot_town_elder),
            (change_screen_trade, ":var_0"),
        (try_end),
    ], "."),

    ("village_attack_bandits", 
    [
        (party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
    ],
    "Attack the bandits.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_village_infested_by_bandits),
        (party_get_slot, ":var_1", "$current_town", slot_town_center),
        (modify_visitors_at_site, ":var_1"),
        (store_random_in_range, "$battle_renown_value", 1, 11),
        (reset_visitors),
        (set_visitors, 0, ":var_0", "$qst_eliminate_bandits_infesting_village_num_bandits"),
        (set_visitors, 2, "trp_farmer", "$qst_eliminate_bandits_infesting_village_num_villagers"),
        (set_party_battle_mode),
        (set_battle_advantage, 0),
        (assign, "$g_battle_result", 0),
        (set_jump_mission, "mt_village_attack_bandits"),
        (jump_to_scene, ":var_1"),
        (assign, "$g_next_menu", "mnu_village_infest_bandits_result"),
        (jump_to_menu, "mnu_battle_debrief"),
        (assign, "$g_mt_mode", 1),
        (change_screen_mission),
    ], "."),

    ("village_wait", 
    [
        (party_slot_eq, "$current_town", 251, 1),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
    ],
    "Wait here for some time.",
    [
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_last_rest_center", "$current_town"),
        (try_begin),
            (party_is_active, "p_main_party"),
            (party_get_current_terrain, ":var_0", "p_main_party"),
            (try_begin),
                (eq, ":var_0", 5),
                (unlock_achievement, 28),
            (try_end),
        (try_end),
        (rest_for_hours_interactive, 168, 5, 1),
        (change_screen_return),
    ], "."),

    ("collect_taxes_qst", 
    [
        (party_slot_eq, "$current_town", slot_village_state, 0),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (check_quest_active, "qst_collect_taxes"),
        (quest_get_slot, ":var_0", "qst_collect_taxes", 6),
        (quest_slot_eq, "qst_collect_taxes", 1, "$current_town"),
        (neg|quest_slot_eq, "qst_collect_taxes", 11, 4),
        (str_store_troop_name, s1, ":var_0"),
        (quest_get_slot, reg5, "qst_collect_taxes", 11),
    ],
    "{reg5?Continue collecting taxes:Collect taxes} due to {s1}.",
    [
        (jump_to_menu, "mnu_collect_taxes"),
    ], "."),

    ("train_peasants_against_bandits_qst", 
    [
        (party_slot_eq, "$current_town", slot_village_state, 0),
        (check_quest_active, "qst_train_peasants_against_bandits"),
        (neg|check_quest_concluded, "qst_train_peasants_against_bandits"),
        (quest_slot_eq, "qst_train_peasants_against_bandits", 1, "$current_town"),
    ],
    "Train the peasants.",
    [
        (jump_to_menu, "mnu_train_peasants_against_bandits"),
    ], "."),

    ("village_hostile_action", 
    [
        (party_slot_eq, "$current_town", slot_village_state, 0),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (neg|eq, "$players_kingdom", "$g_encountered_party_faction"),
    ],
    "Take a hostile action.",
    [
        (jump_to_menu, "mnu_village_hostile_action"),
    ], "."),

    ("village_reports", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! Show reports.",
    [
        (jump_to_menu, "mnu_center_reports"),
    ], "."),

    ("village_leave", [],
    "Leave...",
    [
        (change_screen_return, 0),
    ], "."),

]),

("village_hostile_action", 0,
"What action do you have in mind?",
"none", [],
[
    ("village_take_food", 
    [
        (party_slot_eq, "$current_town", slot_village_state, 0),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (party_get_slot, ":var_0", "$current_town", slot_town_elder),
        (assign, ":var_1", 0),
        (try_for_range, ":var_2", 10, 106),
            (troop_get_inventory_slot, ":var_3", ":var_0", ":var_2"),
            (ge, ":var_3", 0),
            (assign, ":var_1", 1),
        (try_end),
        (eq, ":var_1", 1),
    ],
    "Force the peasants to give you supplies.",
    [
        (jump_to_menu, "mnu_village_take_food_confirm"),
    ], "."),

    ("village_steal_cattle", 
    [
        (party_slot_eq, "$current_town", slot_village_state, 0),
        (party_slot_eq, "$current_town", slot_village_player_can_not_steal_cattle, 0),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (party_get_slot, ":var_0", "$current_town", slot_town_trade_routes_end),
        (neg|party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
        (gt, ":var_0", 0),
    ],
    "Steal cattle.",
    [
        (jump_to_menu, "mnu_village_steal_cattle_confirm"),
    ], "."),

    ("village_loot", 
    [
        (party_slot_eq, "$current_town", slot_village_state, 0),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
        (store_faction_of_party, ":var_0", "$current_town"),
        (store_relation, ":var_1", "fac_player_supporters_faction", ":var_0"),
        (neg|ge, ":var_1", 0),
    ],
    "Loot and burn this village.",
    [
        (jump_to_menu, "mnu_village_start_attack"),
    ], "."),

    ("forget_it", [],
    "Forget it.",
    [
        (jump_to_menu, "mnu_village"),
    ], "."),

]),

("recruit_volunteers", 0,
"{s18}",
"none", 
[
    (party_get_slot, ":var_0", "$current_town", slot_center_volunteer_troop_type),
    (party_get_slot, ":var_1", "$current_town", slot_center_volunteer_troop_amount),
    (party_get_free_companions_capacity, ":var_2", "p_main_party"),
    (store_troop_gold, ":var_3", "trp_player"),
    (store_div, ":var_4", ":var_3", 20),
    (assign, ":var_5", ":var_2"),
    (val_min, ":var_5", ":var_4"),
    (try_begin),
        (gt, ":var_5", 0),
        (val_min, ":var_1", ":var_5"),
    (try_end),
    (assign, reg5, ":var_1"),
    (assign, reg7, 0),
    (try_begin),
        (gt, ":var_1", ":var_4"),
        (assign, reg7, 1),
    (try_end),
    (try_begin),
        (eq, ":var_1", 0),
        (str_store_string, s18, "@No one here seems to be willing to join your party."),
    (else_try),
        (store_mul, reg6, ":var_1", 20),
        (str_store_troop_name_by_count, s3, ":var_0", ":var_1"),
        (try_begin),
            (eq, reg5, 1),
            (str_store_string, s18, "@One {s3} volunteer to follow you for 20 Dinars."),
        (else_try),
            (str_store_string, s18, "@{reg5} {s3} volunteers to follow you for 20 Dinars each."),
        (try_end),
        (set_background_mesh, "mesh_pic_recruits"),
    (try_end),
],
[
    ("continue_not_enough_gold", 
    [
        (eq, reg7, 1),
    ],
    "I don't have enough money...",
    [
        (jump_to_menu, "mnu_village"),
    ], "."),

    ("continue", 
    [
        (eq, reg7, 0),
        (eq, reg5, 0),
    ],
    "Continue...",
    [
        (party_set_slot, "$current_town", slot_center_volunteer_troop_amount, -1),
        (jump_to_menu, "mnu_village"),
    ], "."),

    ("recruit_them", 
    [
        (eq, reg7, 0),
        (gt, reg5, 0),
    ],
    "Recruit them ({reg6} denars).",
    [
        (call_script, "script_village_recruit_volunteers_recruit"),
        (jump_to_menu, "mnu_village"),
    ], "."),

    ("forget_it", 
    [
        (eq, reg7, 0),
        (gt, reg5, 0),
    ],
    "Forget it.",
    [
        (jump_to_menu, "mnu_village"),
    ], "."),

]),

("village_hunt_down_fugitive_defeated", 0,
"A heavy blow from the fugitive sends you to the ground, and your vision spins and goes dark. Time passes. When you open your eyes again you find yourself battered and bloody, but luckily none of the wounds appear to be lethal.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_village"),
    ], "."),

]),

("village_infest_bandits_result", 4096,
"{s9}",
"none", 
[
    (try_begin),
        (eq, "$g_battle_result", 1),
        (jump_to_menu, "mnu_village_infestation_removed"),
    (else_try),
        (str_store_string, s9, "@Try as you might, you could not defeat the bandits. Infuriated, they raze the village to the ground to punish the peasants, and then leave the burning wasteland behind to find greener pastures to plunder."),
        (set_background_mesh, "mesh_pic_looted_village"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (party_set_slot, "$g_encountered_party", slot_village_infested_by_bandits, 0),
        (call_script, "script_village_set_state", "$current_town", 2),
        (party_set_slot, "$current_town", slot_village_raid_progress, 0),
        (party_set_slot, "$current_town", slot_village_recover_progress, 0),
        (try_begin),
            (check_quest_active, "qst_eliminate_bandits_infesting_village"),
            (quest_slot_eq, "qst_eliminate_bandits_infesting_village", 1, "$g_encountered_party"),
            (call_script, "script_change_player_relation_with_center", "$g_encountered_party", -5),
            (call_script, "script_fail_quest", "qst_eliminate_bandits_infesting_village"),
            (call_script, "script_end_quest", "qst_eliminate_bandits_infesting_village"),
        (else_try),
            (check_quest_active, "qst_deal_with_bandits_at_lords_village"),
            (quest_slot_eq, "qst_deal_with_bandits_at_lords_village", 1, "$g_encountered_party"),
            (call_script, "script_change_player_relation_with_center", "$g_encountered_party", -4),
            (call_script, "script_fail_quest", "qst_deal_with_bandits_at_lords_village"),
            (call_script, "script_end_quest", "qst_deal_with_bandits_at_lords_village"),
        (else_try),
            (call_script, "script_change_player_relation_with_center", "$g_encountered_party", -3),
        (try_end),
        (jump_to_menu, "mnu_village"),
    ], "."),

]),

("village_infestation_removed", 512,
"In a battle worthy of song, you and your men drive the bandits out of the village, making it safe once more. The villagers have little left in the way of wealth after their ordeal, but they offer you all they can find.",
"none", 
[
    (party_get_slot, ":var_0", "$g_encountered_party", slot_village_infested_by_bandits),
    (party_set_slot, "$g_encountered_party", slot_village_infested_by_bandits, 0),
    (party_clear, "p_temp_party"),
    (party_add_members, "p_temp_party", ":var_0", "$qst_eliminate_bandits_infesting_village_num_bandits"),
    (assign, "$g_strength_contribution_of_player", 50),
    (call_script, "script_party_give_xp_and_gold", "p_temp_party"),
    (try_begin),
        (check_quest_active, "qst_eliminate_bandits_infesting_village"),
        (quest_slot_eq, "qst_eliminate_bandits_infesting_village", 1, "$g_encountered_party"),
        (call_script, "script_end_quest", "qst_eliminate_bandits_infesting_village"),
        (call_script, "script_change_player_relation_with_center", "$g_encountered_party", 5),
    (else_try),
        (check_quest_active, "qst_deal_with_bandits_at_lords_village"),
        (quest_slot_eq, "qst_deal_with_bandits_at_lords_village", 1, "$g_encountered_party"),
        (call_script, "script_succeed_quest", "qst_deal_with_bandits_at_lords_village"),
        (call_script, "script_change_player_relation_with_center", "$g_encountered_party", 3),
    (else_try),
        (call_script, "script_change_player_relation_with_center", "$g_encountered_party", 4),
    (try_end),
    (party_get_slot, ":var_1", "$current_town", slot_town_elder),
    (try_for_range, ":var_2", 10, 106),
        (store_random_in_range, ":var_3", 0, 100),
        (neg|ge, ":var_3", 70),
        (troop_set_inventory_slot, ":var_1", ":var_2", -1),
    (try_end),
],
[
    ("village_bandits_defeated_accept", [],
    "Take it as your just due.",
    [
        (jump_to_menu, "mnu_village"),
        (party_get_slot, ":var_0", "$current_town", slot_town_elder),
        (troop_sort_inventory, ":var_0"),
        (change_screen_loot, ":var_0"),
    ], "."),

    ("village_bandits_defeated_cont", [],
    "Refuse, stating that they need these items more than you do.",
    [
        (call_script, "script_change_player_relation_with_center", "$g_encountered_party", 3),
        (call_script, "script_change_player_honor", 2),
        (jump_to_menu, "mnu_village"),
    ], "."),

]),

("steward_training", 512,
"The meeting between you and your {s17} steward^is prepared to begin.^^Based on the amount of information your steward needs to learn,^the meeting will last {reg8} hours and cost {reg9} denars.{reg6?^^Unfortunately you do not currently have the funds to hold this meeting...:}",
"none", 
[
    (try_begin),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (str_store_string, s17, "@village"),
    (else_try),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (str_store_string, s17, "@town"),
    (else_try),
        (str_store_string, s17, "@castle"),
    (try_end),
    (party_get_slot, ":var_0", "$g_encountered_party", 293),
    (call_script, "script_pop_check_steward_skills", ":var_0"),
    (try_begin),
        (neg|ge, reg1, 4),
        (assign, reg8, 3),
        (assign, reg9, 450),
    (else_try),
        (gt, reg1, 17),
        (assign, reg8, 18),
        (assign, reg9, 2700),
    (else_try),
        (assign, reg8, reg1),
        (store_mul, ":var_1", reg1, 150),
        (assign, reg9, ":var_1"),
    (try_end),
    (try_begin),
        (assign, reg6, 0),
        (store_troop_gold, ":var_2", "trp_player"),
        (neg|ge, ":var_2", reg9),
        (assign, reg6, 1),
    (try_end),
],
[
    ("steward_training_confirm", 
    [
        (eq, reg6, 0),
    ],
    "Begin the meeting.",
    [
        (party_set_slot, "$current_town", 295, 0),
        (assign, ":var_0", reg9),
        (troop_remove_gold, "trp_player", ":var_0"),
        (party_get_slot, ":var_1", "$current_town", 293),
        (call_script, "script_pop_train_steward", ":var_1"),
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_town_visit_after_rest", 1),
        (assign, "$pop_train_steward_hours", reg8),
        (assign, "$g_last_rest_center", "$current_town"),
        (assign, "$g_last_rest_payment_until", -1),
        (rest_for_hours, 1000, 5, 0),
        (change_screen_return),
    ], "."),

    ("steward_training_decline", [],
    "Put the meeting off until later.",
    [
        (jump_to_menu, "$g_next_menu"),
    ], "."),

]),

("steward_training_complete", 512,
"The meeting with your {s17} steward was a success. He thanks you for your time, returning to {reg9?the castle:his home} with renewed confidence in his abilities.",
"none", 
[
    (assign, reg9, 1),
    (try_begin),
        (party_slot_eq, "$current_town", slot_party_type, 4),
        (str_store_string, s17, "@village"),
        (assign, reg9, 0),
    (else_try),
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (str_store_string, s17, "@town"),
    (else_try),
        (str_store_string, s17, "@castle"),
    (try_end),
    (try_begin),
        (neg|party_slot_eq, "$current_town", slot_party_type, 2),
        (call_script, "script_change_player_relation_with_center", "$current_town", 5),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("center_manage", 0,
"{s19}^{reg6?^^You are currently building {s7}. The current project will be completed after {reg8} day{reg9?s:}.:}",
"none", 
[
    (assign, ":var_0", 0),
    (str_clear, s18),
    (try_begin),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (assign, ":var_1", 250),
        (assign, ":var_2", 273),
        (str_store_string, s17, "@village"),
    (else_try),
        (assign, ":var_1", 262),
        (assign, ":var_2", 289),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (str_store_string, s17, "@town"),
    (else_try),
        (assign, ":var_1", 260),
        (assign, ":var_2", 276),
        (str_store_string, s17, "@castle"),
    (try_end),
    (str_clear, s18),
    (try_for_range, ":var_3", ":var_1", ":var_2"),
        (party_slot_ge, "$g_encountered_party", ":var_3", 1),
        (val_add, ":var_0", 1),
        (assign, reg0, 0),
        (call_script, "script_get_improvement_details", ":var_3", "$g_encountered_party"),
        (party_get_slot, ":var_4", "$g_encountered_party", ":var_3"),
        (eq, ":var_4", 1),
        (str_store_string, s10, "@{s10}"),
        (try_begin),
            (eq, ":var_0", 1),
            (gt, reg10, 1),
            (str_store_string, s18, "@^{s10}"),
        (else_try),
            (gt, reg10, 1),
            (str_store_string, s18, "@{s18}^{s10}."),
        (try_end),
    (try_end),
    (try_for_range, ":var_3", ":var_1", ":var_2"),
        (party_slot_ge, "$g_encountered_party", ":var_3", 1),
        (val_add, ":var_0", 1),
        (assign, reg10, 0),
        (call_script, "script_get_improvement_details", ":var_3", "$g_encountered_party"),
        (party_get_slot, ":var_4", "$g_encountered_party", ":var_3"),
        (is_between, ":var_4", 2, 10),
        (val_mul, ":var_4", 10),
        (assign, reg12, ":var_4"),
        (str_store_string, s10, "@({s10} - {reg12}% Damaged-)"),
        (try_begin),
            (eq, ":var_0", 1),
            (gt, reg10, 1),
            (str_store_string, s18, "@^{s10}"),
        (else_try),
            (gt, reg10, 1),
            (str_store_string, s18, "@{s18}^{s10}."),
        (try_end),
    (try_end),
    (try_begin),
        (eq, ":var_0", 0),
        (str_store_string, s19, "@The {s17} has no improvements."),
    (else_try),
        (str_store_string, s19, "@The {s17} has the following improvements:^^       {s18}."),
    (try_end),
    (assign, reg6, 0),
    (try_begin),
        (party_get_slot, ":var_5", "$g_encountered_party", slot_center_current_improvement),
        (gt, ":var_5", 0),
        (call_script, "script_get_improvement_details", ":var_5", "$g_encountered_party"),
        (gt, reg10, 1),
        (str_store_string, s7, 10),
        (assign, reg6, 1),
        (store_current_hours, ":var_6"),
        (party_get_slot, ":var_7", "$g_encountered_party", slot_center_improvement_end_hour),
        (val_sub, ":var_7", ":var_6"),
        (store_div, reg8, ":var_7", 24),
        (val_max, reg8, 1),
        (store_sub, reg9, reg8, 1),
    (try_end),
],
[
    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "$g_next_menu"),
    ], "."),

    ("severance_of_prisoners", 
    [
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
        (assign, ":var_0", 0),
        (party_get_num_prisoner_stacks, ":var_1", "$current_town"),
        (try_for_range_backwards, ":var_2", 0, ":var_1"),
            (party_prisoner_stack_get_troop_id, ":var_3", "$current_town", ":var_2"),
            (neg|troop_is_hero, ":var_3"),
            (val_add, ":var_0", 1),
        (try_end),
        (ge, ":var_0", 1),
    ],
    "disband prisoners to slaves",
    [
        (jump_to_menu, "mnu_severance_of_prisoner_begin"),
    ], "."),

    ("center_send_out_prospectors", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 1),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 1),
        (party_slot_eq, "$g_encountered_party", 292, 0),
        (party_slot_eq, "$g_encountered_party", 269, 0),
    ],
    "Send out prospectors.",
    [
        (assign, "$g_improvement_type", 292),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_training_grounds", 
    [
        (neg|eq, reg6, 1),
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_trainer, ":var_0"),
        (ge, ":var_1", 4),
        (store_skill_level, ":var_1", skl_weapon_master, ":var_0"),
        (ge, ":var_1", 5),
        (neg|party_slot_eq, "$g_encountered_party", 274, 1),
    ],
    "Build training grounds.",
    [
        (assign, "$g_improvement_type", 274),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_manor", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 251, 1),
    ],
    "Build a manor.",
    [
        (assign, "$g_improvement_type", 251),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_herbalist", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_first_aid, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_wound_treatment, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", slot_town_trade_good_prices_begin, 1),
    ],
    "Build a herbalist.",
    [
        (assign, "$g_improvement_type", 250),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_fishpond", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 1),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 252, 1),
    ],
    "Build fish Pond.",
    [
        (assign, "$g_improvement_type", 252),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_shrine", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_wound_treatment, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 270, 1),
    ],
    "Build shrine.",
    [
        (assign, "$g_improvement_type", 270),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_watch_tower", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 1),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 253, 1),
    ],
    "Build watch tower.",
    [
        (assign, "$g_improvement_type", 253),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_school", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_trainer, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 254, 1),
    ],
    "Build a school.",
    [
        (assign, "$g_improvement_type", 254),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_renderers", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_inventory_management, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 255, 1),
    ],
    "Build renderers.",
    [
        (assign, "$g_improvement_type", 255),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_crop_rotation", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_inventory_management, ":var_0"),
        (ge, ":var_1", 4),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 256, 1),
    ],
    "Implement Crop Rotation.",
    [
        (assign, "$g_improvement_type", 256),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_hunting_lodge", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_tracking, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_pathfinding, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 257, 1),
    ],
    "Build hunting lodge.",
    [
        (assign, "$g_improvement_type", 257),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_improved_roads", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_pathfinding, ":var_0"),
        (ge, ":var_1", 4),
        (neg|party_slot_eq, "$g_encountered_party", 263, 1),
    ],
    "Build improved roads.",
    [
        (assign, "$g_improvement_type", 263),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_warehouse", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_inventory_management, ":var_0"),
        (ge, ":var_1", 4),
        (store_skill_level, ":var_1", skl_trade, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 280, 1),
    ],
    "Build warehouse.",
    [
        (assign, "$g_improvement_type", 280),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_foresters", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_pathfinding, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_tracking, ":var_0"),
        (ge, ":var_1", 4),
        (neg|party_slot_eq, "$g_encountered_party", 258, 1),
    ],
    "Build foresters.",
    [
        (assign, "$g_improvement_type", 258),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_sheriff", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_trainer, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_tracking, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 259, 1),
    ],
    "Build sheriff.",
    [
        (assign, "$g_improvement_type", 259),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_building_civic_patrols", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_tracking, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 1),
        (neg|party_slot_eq, "$g_encountered_party", 288, 1),
    ],
    "Build civic patrols.",
    [
        (assign, "$g_improvement_type", 288),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_prisoner_tower", 
    [
        (neg|eq, reg6, 1),
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_prisoner_management, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 275, 1),
    ],
    "Build prison tower.",
    [
        (assign, "$g_improvement_type", 275),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_market", 
    [
        (neg|eq, reg6, 1),
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_trade, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_looting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 260, 1),
    ],
    "Build market.",
    [
        (assign, "$g_improvement_type", 260),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_blacksmith", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_trade, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 262, 1),
    ],
    "Build blacksmith.",
    [
        (assign, "$g_improvement_type", 262),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_sanitation_standards", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 264, 1),
    ],
    "Implement sanitation standards.",
    [
        (assign, "$g_improvement_type", 264),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_church", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_leadership, ":var_0"),
        (ge, ":var_1", 5),
        (neg|party_slot_eq, "$g_encountered_party", 265, 1),
    ],
    "Build church.",
    [
        (assign, "$g_improvement_type", 265),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_winery", 
    [
        (neg|eq, reg6, 1),
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, 4),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_first_aid, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 4),
        (neg|party_slot_eq, "$g_encountered_party", 261, 1),
    ],
    "Build Winery.",
    [
        (assign, "$g_improvement_type", 261),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_tax_collector", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_looting, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 266, 1),
    ],
    "Build tax collector office.",
    [
        (assign, "$g_improvement_type", 266),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_fire_brigade", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_pathfinding, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 267, 1),
    ],
    "Build fire brigade.",
    [
        (assign, "$g_improvement_type", 267),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_craftsmen", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_trade, ":var_0"),
        (ge, ":var_1", 4),
        (neg|party_slot_eq, "$g_encountered_party", 268, 1),
    ],
    "Build craftsmen.",
    [
        (assign, "$g_improvement_type", 268),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_well_cleaners", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 283, 1),
    ],
    "Build well cleaners.",
    [
        (assign, "$g_improvement_type", 283),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_streetsweepers", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_tracking, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 284, 1),
    ],
    "Build streetsweepers.",
    [
        (assign, "$g_improvement_type", 284),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_building_inspectors", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 285, 1),
    ],
    "Build building inspectors.",
    [
        (assign, "$g_improvement_type", 285),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_mine", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 4),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_trade, ":var_0"),
        (ge, ":var_1", 4),
        (party_slot_ge, "$g_encountered_party", 291, 5),
        (neg|party_slot_eq, "$g_encountered_party", 269, 1),
    ],
    "Build mine.",
    [
        (assign, "$g_improvement_type", 269),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_monastery", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 4),
        (store_skill_level, ":var_1", skl_trainer, ":var_0"),
        (ge, ":var_1", 4),
        (neg|party_slot_eq, "$g_encountered_party", 271, 1),
    ],
    "Build monastery.",
    [
        (assign, "$g_improvement_type", 271),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_messenger_post", 
    [
        (neg|eq, reg6, 1),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_pathfinding, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 272, 1),
    ],
    "Build messenger post.",
    [
        (assign, "$g_improvement_type", 272),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_chapel", 
    [
        (neg|eq, reg6, 1),
        (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 2),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_leadership, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 273, 1),
    ],
    "Build chapel.",
    [
        (assign, "$g_improvement_type", 273),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_hospital", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 3),
        (store_skill_level, ":var_1", skl_surgery, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 3),
        (neg|party_slot_eq, "$g_encountered_party", 276, 1),
    ],
    "Build hospital.",
    [
        (assign, "$g_improvement_type", 276),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_university", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 4),
        (store_skill_level, ":var_1", skl_trainer, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 4),
        (neg|party_slot_eq, "$g_encountered_party", 277, 1),
    ],
    "Build university.",
    [
        (assign, "$g_improvement_type", 277),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_cathedral", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_engineer, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_leadership, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 6),
        (neg|party_slot_eq, "$g_encountered_party", 278, 1),
    ],
    "Build cathedral.",
    [
        (assign, "$g_improvement_type", 278),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_courts", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_prisoner_management, ":var_0"),
        (ge, ":var_1", 2),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 4),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 5),
        (neg|party_slot_eq, "$g_encountered_party", 279, 1),
    ],
    "Build courts.",
    [
        (assign, "$g_improvement_type", 279),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_organized_guilds", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_trade, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 5),
        (neg|party_slot_eq, "$g_encountered_party", 281, 1),
    ],
    "Build organized guilds.",
    [
        (assign, "$g_improvement_type", 281),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_build_lamplighters", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_pathfinding, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 282, 1),
    ],
    "Build lamplighters.",
    [
        (assign, "$g_improvement_type", 282),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_building_thieves_guild", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_looting, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_tactics, ":var_0"),
        (ge, ":var_1", 5),
        (store_skill_level, ":var_1", skl_persuasion, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 286, 1),
    ],
    "Build thieves guild.",
    [
        (assign, "$g_improvement_type", 286),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

    ("center_building_town_crier", 
    [
        (neg|eq, reg6, 1),
        (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
        (party_get_slot, ":var_0", "$g_encountered_party", 293),
        (store_skill_level, ":var_1", skl_spotting, ":var_0"),
        (ge, ":var_1", 2),
        (neg|party_slot_eq, "$g_encountered_party", 287, 1),
    ],
    "Build town crier.",
    [
        (assign, "$g_improvement_type", 287),
        (jump_to_menu, "mnu_center_improve"),
    ], "."),

]),

("center_improve", 0,
"^^ {s19} Your steward, with an engineering skill of ({reg2}), believes that {reg7?repairing:building} the {s4} will cost  {reg5} denars and will take {reg6} days.",
"none", 
[
    (call_script, "script_get_improvement_details", "$g_improvement_type", "$g_encountered_party"),
    (gt, reg10, 0),
    (assign, ":var_0", reg10),
    (party_get_slot, ":var_1", "$g_encountered_party", "$g_improvement_type"),
    (store_sub, reg7, ":var_1", 1),
    (val_clamp, reg7, 0, 2),
    (try_begin),
        (gt, ":var_1", 1),
        (val_mul, ":var_0", ":var_1"),
        (val_div, ":var_0", 10),
    (try_end),
    (str_store_string, s4, 10),
    (str_store_string, s19, 1),
    (party_get_slot, ":var_2", "$g_encountered_party", 293),
    (store_skill_level, ":var_3", "skl_engineer", ":var_2"),
    (assign, reg2, ":var_3"),
    (store_sub, ":var_4", 20, ":var_3"),
    (val_mul, ":var_0", ":var_4"),
    (val_div, ":var_0", 20),
    (store_div, ":var_5", ":var_0", 750),
    (val_add, ":var_5", 3),
    (assign, reg5, ":var_0"),
    (assign, reg6, ":var_5"),
],
[
    ("improve_cont", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", reg5),
    ],
    "Go on.",
    [
        (troop_remove_gold, "trp_player", reg5),
        (party_set_slot, "$g_encountered_party", slot_center_current_improvement, "$g_improvement_type"),
        (store_current_hours, ":var_0"),
        (store_mul, ":var_1", reg6, 24),
        (val_add, ":var_1", ":var_0"),
        (party_set_slot, "$g_encountered_party", slot_center_improvement_end_hour, ":var_1"),
        (jump_to_menu, "mnu_center_manage"),
    ], "."),

    ("forget_it", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", reg5),
    ],
    "Forget it.",
    [
        (jump_to_menu, "mnu_center_manage"),
    ], "."),

    ("improve_not_enough_gold", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (neg|ge, ":var_0", reg5),
    ],
    "I don't have enough money for that.",
    [
        (jump_to_menu, "mnu_center_manage"),
    ], "."),

]),

("town_bandits_failed", 512,
"{s4} {s5}",
"none", 
[
    (store_troop_gold, ":var_0", "trp_player"),
    (store_div, ":var_1", ":var_0", 30),
    (store_random_in_range, ":var_2", 40, 100),
    (val_add, ":var_1", ":var_2"),
    (val_min, ":var_1", ":var_0"),
    (troop_remove_gold, "trp_player", ":var_1"),
    (party_set_slot, "$current_town", slot_center_has_bandits, 0),
    (party_get_num_companions, ":var_3", "p_main_party"),
    (str_store_string, s4, "@The assasins beat you down and leave you for dead. ."),
    (str_store_string, s4, "@You have fallen. The bandits quickly search your body for every coin they can find, then vanish into the night. They have left you alive, if only barely."),
    (try_begin),
        (gt, ":var_3", 2),
        (str_store_string, s5, "@Luckily some of your companions come to search for you when you do not return, and find you lying by the side of the road. They hurry you to safety and dress your wounds."),
    (else_try),
        (str_store_string, s5, "@Luckily some passing townspeople find you lying by the side of the road, and recognise you as something other than a simple beggar. They carry you to the nearest inn and dress your wounds."),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("town_bandits_succeeded", 512,
"The bandits fall before you as wheat to a scythe! Soon you stand alone in the streets while most of your attackers lie unconscious, dead or dying. Searching the bodies, you find a purse which must have belonged to a previous victim of these brutes. Or perhaps, it was given to them by someone who wanted to arrange a suitable ending to your life.",
"none", 
[
    (party_set_slot, "$current_town", slot_center_has_bandits, 0),
    (assign, "$g_last_defeated_bandits_town", "$g_encountered_party"),
    (try_begin),
        (check_quest_active, "qst_deal_with_night_bandits"),
        (neg|check_quest_succeeded, "qst_deal_with_night_bandits"),
        (quest_slot_eq, "qst_deal_with_night_bandits", 1, "$g_encountered_party"),
        (call_script, "script_succeed_quest", "qst_deal_with_night_bandits"),
    (try_end),
    (store_mul, ":var_0", "$num_center_bandits", 117),
    (add_xp_to_troop, ":var_0", "trp_player"),
    (store_mul, ":var_1", "$num_center_bandits", 50),
    (call_script, "script_troop_add_gold", "trp_player", ":var_1"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("village_steal_cattle_confirm", 0,
"As the party member with the highest looting skill ({reg2}), {reg3?you reckon:{s1} reckons} that you can steal as many as {reg4} heads of village's cattle.",
"none", 
[
    (call_script, "script_get_max_skill_of_player_party", "skl_looting"),
    (assign, reg2, reg0),
    (assign, ":var_0", reg1),
    (try_begin),
        (eq, ":var_0", "trp_player"),
        (assign, reg3, 1),
    (else_try),
        (assign, reg3, 0),
        (str_store_troop_name, s1, ":var_0"),
    (try_end),
    (call_script, "script_calculate_amount_of_cattle_can_be_stolen", "$current_town"),
    (assign, reg4, reg0),
],
[
    ("village_steal_cattle_confirm", [],
    "Go on.",
    [
        (rest_for_hours_interactive, 3, 5, 1),
        (assign, "$auto_menu", "mnu_village_steal_cattle"),
        (change_screen_return),
    ], "."),

    ("forget_it", [],
    "Forget it.",
    [
        (change_screen_return),
    ], "."),

]),

("village_steal_cattle", 512,
"{s1}",
"none", 
[
    (call_script, "script_calculate_amount_of_cattle_can_be_stolen", "$current_town"),
    (assign, ":var_0", reg0),
    (val_add, ":var_0", 1),
    (store_random_in_range, ":var_1", 0, ":var_0"),
    (party_set_slot, "$current_town", slot_village_player_can_not_steal_cattle, 1),
    (party_get_slot, ":var_2", "$current_town", slot_town_lord),
    (try_begin),
        (neg|gt, ":var_1", 0),
        (call_script, "script_change_player_relation_with_center", "$current_town", -3),
        (str_store_string, s1, "@You fail to steal any cattle."),
    (else_try),
        (assign, reg17, ":var_1"),
        (store_sub, reg12, ":var_1", 1),
        (try_begin),
            (gt, ":var_2", 0),
            (call_script, "script_change_player_relation_with_troop", ":var_2", -3),
            (call_script, "script_add_log_entry", 66, "trp_player", "$current_town", ":var_2", "$g_encountered_party_faction"),
        (try_end),
        (call_script, "script_change_player_relation_with_center", "$current_town", -5),
        (str_store_string, s1, "@You drive away {reg17} {reg12?heads:head} of cattle from the village's herd."),
        (try_begin),
            (eq, ":var_1", 3),
            (unlock_achievement, 31),
        (try_end),
        (call_script, "script_create_cattle_herd", "$current_town", ":var_1"),
        (party_get_slot, ":var_3", "$current_town", slot_town_trade_routes_end),
        (val_sub, ":var_3", ":var_1"),
        (party_set_slot, "$current_town", slot_town_trade_routes_end, ":var_3"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("village_take_food_confirm", 0,
"It will be difficult to force and threaten the peasants into giving their precious supplies. You think you will need at least one hour.",
"none", [],
[
    ("village_take_food_confirm", [],
    "Go ahead.",
    [
        (rest_for_hours_interactive, 1, 5, 0),
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_town_visit_after_rest", 1),
        (assign, "$auto_enter_menu_in_center", "mnu_village_take_food"),
        (change_screen_return),
    ], "."),

    ("forget_it", [],
    "Forget it.",
    [
        (jump_to_menu, "mnu_village_hostile_action"),
    ], "."),

]),

("village_take_food", 0,
"The villagers grudgingly bring out what they have for you.",
"none", 
[
    (call_script, "script_party_count_members_with_full_health", "p_main_party"),
    (assign, ":var_0", reg0),
    (call_script, "script_party_count_members_with_full_health", "$current_town"),
    (assign, ":var_1", reg0),
    (try_begin),
        (neg|ge, ":var_0", 6),
        (ge, ":var_1", 40),
        (neg|party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
        (jump_to_menu, "mnu_village_start_attack"),
    (try_end),
],
[
    ("take_supplies", [],
    "Take the supplies.",
    [
        (try_begin),
            (party_slot_ge, "$current_town", slot_center_player_relation, -55),
            (try_begin),
                (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
                (call_script, "script_change_player_relation_with_center", "$current_town", -1),
            (else_try),
                (call_script, "script_change_player_relation_with_center", "$current_town", -3),
            (try_end),
        (try_end),
        (party_get_slot, ":var_0", "$current_town", slot_town_lord),
        (try_begin),
            (gt, ":var_0", 1),
            (call_script, "script_change_player_relation_with_troop", ":var_0", -1),
        (try_end),
        (party_get_slot, ":var_1", "$current_town", slot_town_elder),
        (party_get_skill_level, ":var_2", "p_main_party", "skl_looting"),
        (val_mul, ":var_2", 3),
        (store_sub, ":var_3", 70, ":var_2"),
        (try_for_range, ":var_4", 10, 106),
            (store_random_in_range, ":var_5", 0, 100),
            (neg|ge, ":var_5", ":var_3"),
            (troop_set_inventory_slot, ":var_1", ":var_4", -1),
        (try_end),
        (call_script, "script_objectionable_action", 3, "str_steal_from_villagers"),
        (call_script, "script_add_log_entry", 2, "trp_player", "$current_town", -1, -1),
        (store_faction_of_party, ":var_6", "$current_town"),
        (call_script, "script_faction_inflict_war_damage_on_faction", "$players_kingdom", ":var_6", 5),
        (jump_to_menu, "mnu_village"),
        (troop_sort_inventory, ":var_1"),
        (change_screen_loot, ":var_1"),
    ], "."),

    ("let_them_keep_it", [],
    "Let them keep it.",
    [
        (jump_to_menu, "mnu_village"),
    ], "."),

]),

("village_start_attack", 4608,
"Some of the angry villagers grab their tools and prepare to resist you. It looks like you'll have a fight on your hands if you continue.",
"none", 
[
    (set_background_mesh, "mesh_pic_villageriot"),
    (call_script, "script_party_count_members_with_full_health", "p_main_party"),
    (assign, ":var_0", reg0),
    (call_script, "script_party_count_members_with_full_health", "$current_town"),
    (assign, ":var_1", reg0),
    (try_begin),
        (gt, ":var_0", 25),
        (jump_to_menu, "mnu_village_loot_no_resist"),
    (else_try),
        (this_or_next|eq, ":var_1", 0),
        (eq, "$g_battle_result", 1),
        (try_begin),
            (eq, "$g_battle_result", 1),
            (store_random_in_range, ":var_2", -30, -15),
            (call_script, "script_change_player_relation_with_center", "$current_town", ":var_2"),
            (party_get_slot, ":var_3", "$current_town", slot_town_lord),
            (gt, ":var_3", 0),
            (call_script, "script_change_player_relation_with_troop", ":var_3", -3),
        (try_end),
        (jump_to_menu, "mnu_village_loot_no_resist"),
    (else_try),
        (eq, "$g_battle_result", -1),
        (jump_to_menu, "mnu_village_loot_defeat"),
    (try_end),
],
[
    ("village_raid_attack", [],
    "Charge them.",
    [
        (store_random_in_range, ":var_0", -10, -5),
        (call_script, "script_change_player_relation_with_center", "$current_town", ":var_0"),
        (try_begin),
            (party_get_slot, ":var_1", "$current_town", slot_town_lord),
            (gt, ":var_1", 0),
            (call_script, "script_change_player_relation_with_troop", ":var_1", -3),
        (try_end),
        (assign, "$battle_renown_value", 0),
        (call_script, "script_calculate_battle_advantage"),
        (set_battle_advantage, reg0),
        (set_party_battle_mode),
        (assign, "$g_battle_result", 0),
        (assign, "$g_village_raid_evil", 1),
        (set_jump_mission, "mt_village_raid"),
        (party_get_slot, ":var_2", "$current_town", slot_town_center),
        (jump_to_scene, ":var_2"),
        (assign, "$g_next_menu", "mnu_village_start_attack"),
        (call_script, "script_diplomacy_party_attacks_neutral", "p_main_party", "$g_encountered_party"),
        (call_script, "script_objectionable_action", 3, "str_loot_village"),
        (val_add, "$g_villages_raided", 1),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

    ("village_raid_leave", [],
    "Leave this village alone.",
    [
        (change_screen_return),
    ], "."),

]),

("village_loot_no_resist", 0,
"The villagers here are few and frightened, and they quickly scatter and run before you. The village is at your mercy.",
"none", [],
[
    ("village_loot", [],
    "Plunder the village, then raze it.",
    [
        (call_script, "script_village_set_state", "$current_town", 1),
        (party_set_slot, "$current_town", slot_village_raided_by, "p_main_party"),
        (assign, "$g_player_raiding_village", "$current_town"),
        (try_begin),
            (store_faction_of_party, ":var_0", "$current_town"),
            (store_relation, ":var_1", "$players_kingdom", ":var_0"),
            (ge, ":var_1", 0),
            (call_script, "script_diplomacy_party_attacks_neutral", "p_main_party", "$current_town"),
        (try_end),
        (rest_for_hours, 3, 5, 1),
        (change_screen_return),
    ], "."),

    ("village_raid_leave", [],
    "Leave this village alone.",
    [
        (change_screen_return),
    ], "."),

]),

("village_loot_complete", 512,
"On your orders your troops sack the village, pillaging everything of any value, and then put the buildings to the torch. From the coins and valuables that are found, you get your share of {reg1} denars.",
"none", 
[
    (get_achievement_stat, ":var_0", 30, 0),
    (get_achievement_stat, ":var_1", 30, 1),
    (val_add, ":var_0", 1),
    (set_achievement_stat, 30, 0, ":var_0"),
    (party_set_slot, "$current_town", 40, "trp_player"),
    (try_begin),
        (ge, ":var_0", 3),
        (ge, ":var_1", 3),
        (unlock_achievement, 30),
    (try_end),
    (party_get_slot, ":var_2", "$current_town", slot_town_lord),
    (try_begin),
        (gt, ":var_2", 0),
        (call_script, "script_change_player_relation_with_troop", ":var_2", -5),
    (try_end),
    (store_random_in_range, ":var_3", -35, -25),
    (call_script, "script_change_player_relation_with_center", "$current_town", ":var_3"),
    (store_faction_of_party, ":var_4", "$current_town"),
    (store_relation, ":var_5", ":var_4", "fac_player_supporters_faction"),
    (try_begin),
        (neg|ge, ":var_5", 0),
        (call_script, "script_change_player_relation_with_faction", ":var_4", -3),
    (try_end),
    (assign, ":var_6", 50),
    (party_get_slot, ":var_7", "$current_town", slot_town_prosperity),
    (store_mul, ":var_8", ":var_7", 5),
    (val_add, ":var_6", ":var_8"),
    (call_script, "script_troop_add_gold", "trp_player", ":var_6"),
    (assign, ":var_9", 3),
    (store_div, ":var_10", ":var_6", 100),
    (val_add, ":var_9", ":var_10"),
    (call_script, "script_change_player_party_morale", ":var_9"),
    (faction_get_slot, ":var_11", ":var_4", slot_faction_morale_of_player_troops),
    (store_mul, ":var_12", ":var_9", 200),
    (val_sub, ":var_11", ":var_12"),
    (faction_set_slot, ":var_4", slot_faction_morale_of_player_troops, ":var_11"),
    (call_script, "script_objectionable_action", 3, "str_loot_village"),
    (val_add, "$g_villages_raided", 1),
    (assign, reg1, ":var_6"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_close"),
        (call_script, "script_calculate_amount_of_cattle_can_be_stolen", "$current_town"),
        (assign, ":var_0", reg0),
        (val_mul, ":var_0", 3),
        (val_div, ":var_0", 2),
        (party_get_slot, ":var_1", "$current_town", slot_town_trade_routes_end),
        (val_min, ":var_0", ":var_1"),
        (val_add, ":var_0", 1),
        (store_random_in_range, ":var_2", 0, ":var_0"),
        (try_begin),
            (gt, ":var_2", 0),
            (call_script, "script_create_cattle_herd", "$current_town", ":var_2"),
            (val_sub, ":var_1", ":var_2"),
            (party_set_slot, "$current_town", slot_town_trade_routes_end, ":var_1"),
        (try_end),
        (troop_clear_inventory, "trp_temp_troop"),
        (reset_item_probabilities, 100),
        (troop_add_merchandise, "trp_temp_troop", 11, 45),
        (troop_sort_inventory, "trp_temp_troop"),
        (change_screen_loot, "trp_temp_troop"),
    ], "."),

]),

("village_loot_defeat", 4096,
"Fighting with courage and determination, the villagers manage to hold together and drive off your forces.",
"none", 
[
    (set_background_mesh, "mesh_pic_villageriot"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("village_loot_continue", 0,
"Do you wish to continue looting this village?",
"none", [],
[
    ("disembark_yes", [],
    "Yes.",
    [
        (rest_for_hours, 3, 5, 1),
        (change_screen_return),
    ], "."),

    ("disembark_no", [],
    "No.",
    [
        (call_script, "script_village_set_state", "$current_town", 0),
        (party_set_slot, "$current_town", slot_village_raided_by, -1),
        (assign, "$g_player_raiding_village", 0),
        (change_screen_return),
    ], "."),

]),

("close", 0,
"Nothing.",
"none", 
[
    (change_screen_return),
],
[
]),

("noldor_castle", 4352,
"You approach the Noldor castle, hardly believing it is a reality, not merely a myth ...",
"none", 
[
    (store_encountered_party, "$current_town"),
    (try_begin),
        (eq, "$g_leave_town", 1),
        (assign, "$g_leave_town", 0),
        (rest_for_hours, 1, 5, 0),
        (leave_encounter),
        (change_screen_return),
    (try_end),
],
[
    ("castle_castle", [],
    "Go to the Noldor castle hall.",
    [
        (assign, "$town_entered", 1),
        (call_script, "script_enter_court", "$current_town"),
    ], "Door to the castle."),

    ("join_tournament", 
    [
        (neg|is_currently_night),
        (party_slot_ge, "$current_town", slot_town_has_tournament, 1),
    ],
    "Join the Noldor tournament.",
    [
        (call_script, "script_fill_tournament_participants_troop", "$current_town", 1),
        (assign, "$g_tournament_cur_tier", 0),
        (assign, "$g_tournament_player_team_won", -1),
        (assign, "$g_tournament_bet_placed", 0),
        (assign, "$g_tournament_bet_win_amount", 0),
        (assign, "$g_tournament_last_bet_tier", -1),
        (assign, "$g_tournament_next_num_teams", 0),
        (assign, "$g_tournament_next_team_size", 0),
        (jump_to_menu, "mnu_town_tournament"),
    ], "."),

    ("castle_inspect", [],
    "Take a walk around the courtyard.",
    [
        (try_begin),
            (assign, "$talk_context", 0),
            (assign, "$g_mt_mode", 0),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (assign, ":var_1", 40),
            (party_get_num_companion_stacks, ":var_2", "$g_encountered_party"),
            (try_for_range, ":var_3", 0, ":var_2"),
                (neg|ge, ":var_1", 47),
                (party_stack_get_troop_id, ":var_4", "$g_encountered_party", ":var_3"),
                (neg|troop_is_hero, ":var_4"),
                (party_stack_get_size, ":var_5", "$g_encountered_party", ":var_3"),
                (party_stack_get_num_wounded, ":var_6", "$g_encountered_party", ":var_3"),
                (val_sub, ":var_5", ":var_6"),
                (gt, ":var_5", 0),
                (party_stack_get_troop_dna, ":var_7", "$g_encountered_party", ":var_3"),
                (set_visitor, ":var_1", ":var_4", ":var_7"),
                (val_add, ":var_1", 1),
            (try_end),
            (try_begin),
                (eq, "$town_entered", 0),
                (assign, "$town_entered", 1),
            (try_end),
            (set_jump_entry, 1),
            (assign, ":var_8", 256),
            (set_jump_mission, "mt_castle_visit"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 0, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 1, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 2, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 3, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 4, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 5, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 6, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 7, ":var_8"),
            (jump_to_scene, ":var_0"),
            (change_screen_mission),
        (try_end),
    ], "To the castle courtyard."),

    ("castle_attack", 
    [
        (neg|troop_is_wounded, "trp_player"),
    ],
    "Launch a surprise attack on the castle.",
    [
        (jump_to_menu, "mnu_noldor_attack_verify"),
    ], "."),

    ("castle_wait", 
    [
        (assign, ":var_0", 1),
        (str_clear, s1),
        (try_begin),
            (party_get_num_companions, ":var_1", "p_main_party"),
            (store_div, reg1, ":var_1", 4),
            (val_add, reg1, 1),
            (str_store_string, s1, "@ ({reg1} denars per night)"),
            (store_troop_gold, ":var_2", "trp_player"),
            (neg|ge, ":var_2", reg1),
            (assign, ":var_0", 0),
        (try_end),
        (eq, ":var_0", 1),
    ],
    "Wait here for some time{s1}.",
    [
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_last_rest_center", "$current_town"),
        (assign, "$g_last_rest_payment_until", -1),
        (rest_for_hours_interactive, 168, 5, 0),
        (change_screen_return),
    ], "."),

    ("town_leave", [],
    "Leave...",
    [
        (assign, "$g_permitted_to_center", 0),
        (change_screen_return, 0),
    ], "Leave Area."),

]),

("noldor_attack_verify", 0,
"Are you sure you want to attack the Noldor castle? This is a very treacherous act with dire consequences.",
"none", [],
[
    ("noldor_attack_verify_yes", [],
    "Yes. There's plenty of loot around here masquerading as pointy-eared twats.",
    [
        (jump_to_menu, "mnu_noldor_castle_attack"),
    ], "."),

    ("noldor_attack_verify_no", [],
    "No, we can't stab our Noldor friends in the back!",
    [
        (jump_to_menu, "mnu_noldor_castle"),
    ], "."),

]),

("noldor_castle_attack", 4352,
"Your troops prepare to assault the Noldor castle...",
"none", 
[
    (troop_get_type, ":var_0", "trp_player"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_siege_sighted_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_siege_sighted"),
    (try_end),
],
[
    ("castle_lead_attack", 
    [
        (assign, "$g_enemy_party", "$g_encountered_party"),
        (assign, "$g_ally_party", -1),
        (str_store_party_name, s2, "$g_encountered_party"),
        (call_script, "script_encounter_calculate_fit"),
        (assign, "$all_doors_locked", 1),
        (assign, "$current_town", "$g_encountered_party"),
        (try_begin),
            (eq, "$new_encounter", 1),
            (assign, "$new_encounter", 0),
            (call_script, "script_let_nearby_parties_join_current_battle", 1, 0),
            (call_script, "script_encounter_init_variables"),
            (assign, "$entry_to_town_forbidden", 0),
            (assign, "$sneaked_into_town", 0),
            (assign, "$town_entered", 0),
            (assign, "$encountered_party_hostile", 0),
            (assign, "$encountered_party_friendly", 0),
        (try_end),
    ],
    "Lead the assault.",
    [
        (party_get_slot, ":var_0", "$g_encountered_party", slot_town_center),
        (call_script, "script_calculate_renown_value"),
        (call_script, "script_calculate_battle_advantage"),
        (assign, ":var_1", reg0),
        (val_mul, ":var_1", 2),
        (val_div, ":var_1", 3),
        (set_battle_advantage, ":var_1"),
        (set_party_battle_mode),
        (assign, "$g_siege_battle_state", 1),
        (set_jump_mission, "mt_castle_attack_walls_ladder"),
        (assign, "$cant_talk_to_enemy", 0),
        (assign, "$g_siege_final_menu", "mnu_noldor_castle_attack_result"),
        (assign, "$g_next_menu", "mnu_noldor_castle_attack_result"),
        (jump_to_scene, ":var_0"),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

]),

("noldor_castle_attack_result", 4352,
"Castle attack result - you should not see this text!",
"none", 
[
    (assign, "$g_enemy_party", "$g_encountered_party"),
    (assign, "$g_ally_party", -1),
    (str_store_party_name, s1, "$g_encountered_party"),
    (call_script, "script_encounter_calculate_fit"),
    (assign, reg11, "$g_enemy_fit_for_battle"),
    (assign, reg10, "$g_friend_fit_for_battle"),
    (try_begin),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (else_try),
        (call_script, "script_party_count_fit_regulars", "p_collective_enemy"),
        (assign, ":var_0", 0),
        (try_begin),
            (eq, "$g_battle_result", 1),
            (assign, ":var_0", 1),
        (else_try),
            (neg|gt, "$g_enemy_fit_for_battle", 0),
            (ge, "$g_friend_fit_for_battle", 1),
            (assign, ":var_0", 1),
        (try_end),
        (this_or_next|eq, ":var_0", 1),
        (eq, "$g_enemy_surrenders", 1),
        (assign, "$g_next_menu", "mnu_noldor_castle_victory"),
        (jump_to_menu, "mnu_total_victory"),
    (else_try),
        (assign, "$g_next_menu", "mnu_noldor_castle_defeat"),
        (jump_to_menu, "mnu_total_defeat"),
    (try_end),
    (call_script, "script_set_player_relation_with_faction", "fac_noldor_elves", -50),
    (call_script, "script_change_player_honor", -20),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("noldor_castle_victory", 4096,
"Your treacherous assault has been successful. Just as you leave with wagons of loot, the Noldor castle flickers out of sight as it never existed.",
"none", 
[
    (set_background_mesh, "mesh_pic_victory"),
    (party_clear, "p_castle_noldor"),
    (party_add_members, "p_castle_noldor", "trp_noldor_knight", 50),
    (party_add_members, "p_castle_noldor", "trp_noldor_maiden", 50),
    (party_add_members, "p_castle_noldor", "trp_noldor_noble", 100),
    (party_add_members, "p_castle_noldor", "trp_noldor_ranger", 300),
    (party_add_members, "p_castle_noldor", "trp_noldor_warrior", 500),
    (party_add_prisoners, "p_castle_noldor", "trp_jatu_lancer", 100),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("noldor_castle_defeat", 4096,
"The Noldor have repelled your treacherous assault and cloaked their castle again.",
"none", 
[
    (set_background_mesh, "mesh_pic_defeat"),
    (party_clear, "p_castle_noldor"),
    (party_add_members, "p_castle_noldor", "trp_noldor_knight", 50),
    (party_add_members, "p_castle_noldor", "trp_noldor_maiden", 50),
    (party_add_members, "p_castle_noldor", "trp_noldor_noble", 100),
    (party_add_members, "p_castle_noldor", "trp_noldor_ranger", 300),
    (party_add_members, "p_castle_noldor", "trp_noldor_warrior", 500),
    (party_add_prisoners, "p_castle_noldor", "trp_jatu_lancer", 100),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("stronghold", 4352,
"{s4}",
"none", 
[
    (store_encountered_party, "$current_town"),
    (try_begin),
        (check_quest_active, "qst_order_grandmaster"),
        (quest_slot_eq, "qst_order_grandmaster", 11, 4),
        (str_store_string, s4, "@As you near the Snake Cult stronghold, you can see its many defenders manning the walls. It may be a bloody day."),
    (else_try),
        (quest_slot_eq, "qst_order_grandmaster", 11, 6),
        (eq, "$order_stronghold_upgrade_days", 0),
        (str_store_string, s4, "@The fully rebuilt Order fortress conveys an impression of strength and permanence."),
    (else_try),
        (str_store_string, s4, "@The Order stronghold seems welcoming now that it's cleansed of every trace of Cultist presence."),
    (try_end),
    (set_background_mesh, "mesh_pic_castle1"),
],
[
    ("castle_castle", 
    [
        (eq, 1, 0),
    ],
    "Go to the castle.",
    [
    ], "."),

    ("join_tournament", 
    [
        (eq, 1, 0),
    ],
    "Join the Order tournament.",
    [
    ], "."),

    ("town_castle", 
    [
        (quest_slot_ge, "qst_order_grandmaster", 11, 5),
    ],
    "Go to the Order castle hall.",
    [
        (assign, "$town_entered", 1),
        (call_script, "script_enter_court", "$current_town"),
    ], "Door to the castle."),

    ("town_center", 
    [
        (eq, 1, 0),
    ],
    "Take a walk around the streets.",
    [
    ], "."),

    ("town_tavern", 
    [
        (eq, 1, 0),
    ],
    "Visit the tavern.",
    [
    ], "."),

    ("town_merchant", 
    [
        (eq, 1, 0),
    ],
    "Speak with the merchant.",
    [
    ], "."),

    ("town_arena", 
    [
        (eq, 1, 0),
    ],
    "Enter the arena.",
    [
    ], "."),

    ("town_dungeon", 
    [
        (eq, 1, 0),
    ],
    "Never: Enter the prison.",
    [
    ], "."),

    ("castle_inspect", 
    [
        (quest_slot_ge, "qst_order_grandmaster", 11, 5),
    ],
    "Take a walk around the courtyard.",
    [
        (try_begin),
            (assign, "$talk_context", 0),
            (assign, "$g_mt_mode", 0),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (assign, ":var_1", 40),
            (party_get_num_companion_stacks, ":var_2", "$g_encountered_party"),
            (try_for_range, ":var_3", 0, ":var_2"),
                (neg|ge, ":var_1", 47),
                (party_stack_get_troop_id, ":var_4", "$g_encountered_party", ":var_3"),
                (neg|troop_is_hero, ":var_4"),
                (party_stack_get_size, ":var_5", "$g_encountered_party", ":var_3"),
                (party_stack_get_num_wounded, ":var_6", "$g_encountered_party", ":var_3"),
                (val_sub, ":var_5", ":var_6"),
                (gt, ":var_5", 0),
                (party_stack_get_troop_dna, ":var_7", "$g_encountered_party", ":var_3"),
                (set_visitor, ":var_1", ":var_4", ":var_7"),
                (val_add, ":var_1", 1),
            (try_end),
            (try_begin),
                (eq, "$town_entered", 0),
                (assign, "$town_entered", 1),
            (try_end),
            (set_jump_entry, 1),
            (assign, ":var_8", 256),
            (set_jump_mission, "mt_castle_visit"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 0, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 1, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 2, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 3, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 4, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 5, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 6, ":var_8"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 7, ":var_8"),
            (jump_to_scene, ":var_0"),
            (change_screen_mission),
        (try_end),
    ], "To the castle courtyard."),

    ("town_enterprise", 
    [
        (eq, 1, 0),
    ],
    "Visit your enterprise.",
    [
    ], "."),

    ("visit_lady", 
    [
        (eq, 1, 0),
    ],
    "Attempt to visit a lady.",
    [
    ], "."),

    ("trade_with_merchants", 
    [
        (eq, 1, 0),
    ],
    "Go to the marketplace.",
    [
    ], "."),

    ("castle_attack", 
    [
        (neg|troop_is_wounded, "trp_player"),
        (check_quest_active, "qst_order_grandmaster"),
        (quest_slot_eq, "qst_order_grandmaster", 11, 4),
    ],
    "Launch the assault!",
    [
        (jump_to_menu, "mnu_stronghold_attack_verify"),
    ], "."),

    ("castle_wait", 
    [
        (quest_slot_ge, "qst_order_grandmaster", 11, 5),
    ],
    "Rest here for some time.",
    [
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_last_rest_center", "$current_town"),
        (assign, "$g_last_rest_payment_until", -1),
        (rest_for_hours_interactive, 168, 5, 0),
        (change_screen_return),
    ], "."),

    ("town_leave", [],
    "Leave...",
    [
        (assign, "$g_permitted_to_center", 0),
        (change_screen_return, 0),
    ], "Leave Area."),

]),

("stronghold_attack_verify", 0,
"Are you ready to assault the stronghold?",
"none", [],
[
    ("stronghold_attack_verify_yes", [],
    "Yes. I have fine troops at my command.",
    [
        (jump_to_menu, "mnu_stronghold_attack"),
    ], "."),

    ("stronghold_attack_verify_no", [],
    "No, it looks suicidal.",
    [
        (jump_to_menu, "mnu_stronghold"),
    ], "."),

]),

("stronghold_attack", 4352,
"Your troops prepare to assault the Snake Cult stronghold...",
"none", 
[
    (troop_get_type, ":var_0", "trp_player"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_siege_sighted_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_siege_sighted"),
    (try_end),
],
[
    ("castle_lead_attack", 
    [
        (assign, "$g_enemy_party", "$g_encountered_party"),
        (assign, "$g_ally_party", -1),
        (str_store_party_name, s2, "$g_encountered_party"),
        (call_script, "script_encounter_calculate_fit"),
        (assign, "$all_doors_locked", 1),
        (assign, "$current_town", "$g_encountered_party"),
        (try_begin),
            (eq, "$new_encounter", 1),
            (assign, "$new_encounter", 0),
            (call_script, "script_let_nearby_parties_join_current_battle", 1, 0),
            (call_script, "script_encounter_init_variables"),
            (assign, "$entry_to_town_forbidden", 0),
            (assign, "$sneaked_into_town", 0),
            (assign, "$town_entered", 0),
            (assign, "$encountered_party_hostile", 0),
            (assign, "$encountered_party_friendly", 0),
        (try_end),
    ],
    "Lead the assault.",
    [
        (party_get_slot, ":var_0", "$g_encountered_party", slot_town_center),
        (call_script, "script_calculate_renown_value"),
        (call_script, "script_calculate_battle_advantage"),
        (assign, ":var_1", reg0),
        (val_mul, ":var_1", 2),
        (val_div, ":var_1", 3),
        (set_battle_advantage, ":var_1"),
        (set_party_battle_mode),
        (assign, "$g_siege_battle_state", 1),
        (set_jump_mission, "mt_castle_attack_walls_ladder"),
        (assign, "$cant_talk_to_enemy", 0),
        (assign, "$g_siege_final_menu", "mnu_stronghold_attack_result"),
        (assign, "$g_next_menu", "mnu_stronghold_attack_result"),
        (jump_to_scene, ":var_0"),
        (jump_to_menu, "mnu_battle_debrief"),
        (change_screen_mission),
    ], "."),

]),

("stronghold_attack_result", 4352,
"Castle attack result - you should not see this text!",
"none", 
[
    (assign, "$g_enemy_party", "$g_encountered_party"),
    (assign, "$g_ally_party", -1),
    (str_store_party_name, s1, "$g_encountered_party"),
    (call_script, "script_encounter_calculate_fit"),
    (assign, reg11, "$g_enemy_fit_for_battle"),
    (assign, reg10, "$g_friend_fit_for_battle"),
    (try_begin),
        (eq, "$g_leave_encounter", 1),
        (change_screen_return),
    (else_try),
        (call_script, "script_party_count_fit_regulars", "p_collective_enemy"),
        (assign, ":var_0", 0),
        (try_begin),
            (eq, "$g_battle_result", 1),
            (assign, ":var_0", 1),
        (else_try),
            (neg|gt, "$g_enemy_fit_for_battle", 0),
            (ge, "$g_friend_fit_for_battle", 1),
            (assign, ":var_0", 1),
        (try_end),
        (this_or_next|eq, ":var_0", 1),
        (eq, "$g_enemy_surrenders", 1),
        (assign, "$g_next_menu", "mnu_stronghold_victory"),
        (jump_to_menu, "mnu_total_victory"),
    (else_try),
        (assign, "$g_next_menu", "mnu_stronghold_defeat"),
        (jump_to_menu, "mnu_total_defeat"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("stronghold_victory", 4096,
"The day is won! The last Cultist defender is put to the sword and you claim their stronghold for your Order.",
"none", 
[
    (set_background_mesh, "mesh_pic_victory"),
    (troop_get_slot, ":var_0", "trp_player", 162),
    (store_sub, ":var_1", ":var_0", "trp_dragon_knight"),
    (val_add, ":var_1", "trp_dragon_drake"),
    (store_troop_faction, ":var_2", ":var_0"),
    (faction_set_slot, ":var_2", slot_faction_guard_troop, ":var_1"),
    (party_set_faction, "p_snake_stronghold", ":var_2"),
    (party_set_name, "p_snake_stronghold", "@Order Stronghold"),
    (party_set_flags, "p_snake_stronghold", 16384, 1),
    (party_clear, "p_snake_stronghold"),
    (party_add_members, "p_snake_stronghold", ":var_0", 10),
    (party_add_members, "p_snake_stronghold", ":var_1", 20),
    (party_add_prisoners, "p_snake_stronghold", "trp_snake_follower", 20),
    (quest_set_slot, "qst_order_grandmaster", 11, 5),
    (str_store_string, s3, "@Report news of your victory to your Order."),
    (add_quest_note_from_sreg, "qst_order_grandmaster", 2, 3, 0),
    (display_message, "str_quest_log_updated", 0x66CCFF),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("stronghold_defeat", 4096,
"The Snake Cult have repelled your futile assault and will surely reinforce their garrison before the next one.",
"none", 
[
    (set_background_mesh, "mesh_pic_defeat"),
    (party_add_members, "p_snake_stronghold", "trp_snake_priestess", 5),
    (party_add_members, "p_snake_stronghold", "trp_anaconda_knight", 5),
    (party_add_members, "p_snake_stronghold", "trp_cobra_warrior", 10),
    (party_add_members, "p_snake_stronghold", "trp_snake_armsman", 30),
    (party_add_members, "p_snake_stronghold", "trp_snake_follower", 50),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("town", 4352,
"{s10} {s14}^{s11}{s12}{s13}",
"none", 
[
    (call_script, "script_detect_load_restore_custom_troops"),
    (try_begin),
        (eq, "$sneaked_into_town", 1),
        (call_script, "script_music_set_situation_with_culture", 16384),
    (else_try),
        (call_script, "script_music_set_situation_with_culture", 65536),
    (try_end),
    (store_encountered_party, "$current_town"),
    (try_begin),
        (party_get_slot, ":var_0", "$current_town", slot_town_lord),
        (ge, ":var_0", 0),
        (set_fixed_point_multiplier, 100),
        (position_set_x, pos0, 70),
        (position_set_y, pos0, 5),
        (position_set_z, pos0, 75),
        (set_game_menu_tableau_mesh, "tableau_troop_note_mesh", ":var_0", pos0),
    (try_end),
    (call_script, "script_update_center_recon_notes", "$current_town"),
    (assign, "$g_defending_against_siege", 0),
    (str_clear, s3),
    (party_get_battle_opponent, ":var_0", "$current_town"),
    (store_faction_of_party, ":var_1", "$g_encountered_party"),
    (store_relation, ":var_2", ":var_1", "fac_player_supporters_faction"),
    (try_begin),
        (gt, ":var_0", 0),
        (ge, ":var_2", 0),
        (store_faction_of_party, ":var_3", ":var_0"),
        (store_relation, ":var_4", ":var_3", "fac_player_supporters_faction"),
        (this_or_next|party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
        (neg|ge, ":var_4", 0),
        (assign, "$g_defending_against_siege", 1),
        (assign, "$g_siege_first_encounter", 1),
        (jump_to_menu, "mnu_siege_started_defender"),
    (try_end),
    (try_begin),
        (is_between, "$g_encountered_party", "p_town_1", "p_castle_1"),
        (store_sub, ":var_5", "$g_encountered_party", "p_town_1"),
        (set_achievement_stat, 26, ":var_5", 1),
        (assign, ":var_6", 0),
        (try_for_range, ":var_7", "p_town_1", "p_castle_1"),
            (store_sub, ":var_5", ":var_7", "p_town_1"),
            (get_achievement_stat, ":var_8", 26, ":var_5"),
            (eq, ":var_8", 0),
            (assign, ":var_6", 1),
        (try_end),
        (try_begin),
            (eq, ":var_6", 0),
            (unlock_achievement, 26),
        (try_end),
    (try_end),
    (assign, "$qst_collect_taxes_currently_collecting", 0),
    (try_begin),
        (gt, "$quest_auto_menu", 0),
        (jump_to_menu, "$quest_auto_menu"),
        (assign, "$quest_auto_menu", 0),
    (try_end),
    (try_begin),
        (eq, "$g_town_assess_trade_goods_after_rest", 1),
        (assign, "$g_town_assess_trade_goods_after_rest", 0),
        (jump_to_menu, "mnu_town_trade_assessment"),
    (try_end),
    (assign, "$talk_context", 0),
    (assign, "$all_doors_locked", 0),
    (try_begin),
        (eq, "$g_town_visit_after_rest", 1),
        (assign, "$g_town_visit_after_rest", 0),
        (assign, "$town_entered", 1),
    (try_end),
    (try_begin),
        (eq, "$g_leave_town", 1),
        (assign, "$g_leave_town", 0),
        (assign, "$g_permitted_to_center", 0),
        (leave_encounter),
        (change_screen_return),
    (try_end),
    (str_store_party_name, s2, "$current_town"),
    (party_get_slot, ":var_9", "$current_town", slot_town_lord),
    (store_faction_of_party, ":var_10", "$current_town"),
    (str_store_faction_name, s9, ":var_10"),
    (try_begin),
        (ge, ":var_9", 0),
        (str_store_troop_name, s8, ":var_9"),
        (str_store_string, s7, "@{s8} of the {s9}"),
    (try_end),
    (try_begin),
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (str_store_string, s60, 2),
        (party_get_slot, ":var_11", "$current_town", slot_town_prosperity),
        (try_begin),
            (ge, "$cheat_mode", 1),
            (assign, reg4, ":var_11"),
            (display_message, "@{!}DEBUG -- Prosperity: {reg4}"),
        (try_end),
        (try_begin),
            (neg|gt, ":var_11", 3),
            (assign, ":var_12", 0),
        (else_try),
            (neg|gt, ":var_11", 9),
            (assign, ":var_12", 1),
        (else_try),
            (neg|gt, ":var_11", 24),
            (assign, ":var_12", 2),
        (else_try),
            (neg|gt, ":var_11", 45),
            (assign, ":var_12", 3),
        (else_try),
            (neg|gt, ":var_11", 75),
            (assign, ":var_12", 4),
        (else_try),
            (neg|gt, ":var_11", 117),
            (assign, ":var_12", 5),
        (else_try),
            (neg|gt, ":var_11", 183),
            (assign, ":var_12", 6),
        (else_try),
            (neg|gt, ":var_11", 225),
            (assign, ":var_12", 7),
        (else_try),
            (neg|gt, ":var_11", 255),
            (assign, ":var_12", 8),
        (else_try),
            (neg|gt, ":var_11", 276),
            (assign, ":var_12", 9),
        (else_try),
            (neg|gt, ":var_11", 291),
            (assign, ":var_12", 10),
        (else_try),
            (neg|gt, ":var_11", 297),
            (assign, ":var_12", 11),
        (else_try),
            (gt, ":var_11", 297),
            (assign, ":var_12", 12),
        (try_end),
        (store_add, ":var_13", "str_town_prosperity_0", ":var_12"),
        (str_store_string, s10, ":var_13"),
        (store_div, ":var_13", ":var_11", 60),
        (val_min, ":var_13", 4),
        (val_add, ":var_13", "str_town_alt_prosperity_0"),
        (str_store_string, s14, ":var_13"),
    (else_try),
        (str_clear, s14),
        (str_store_string, s10, "@You are at {s2}."),
    (try_end),
    (call_script, "script_gender_to_reg63"),
    (try_begin),
        (party_slot_eq, "$current_town", slot_party_type, 2),
        (try_begin),
            (eq, ":var_9", "trp_player"),
            (str_store_string, s11, "@ Your own banner flies over the castle gate."),
        (else_try),
            (gt, ":var_9", -1),
            (troop_slot_eq, ":var_9", slot_troop_spouse, "trp_player"),
            (str_store_string, s11, "str__you_see_the_banner_of_your_wifehusband_s7_over_the_castle_gate"),
        (else_try),
            (ge, ":var_9", 0),
            (str_store_string, s11, "@ You see the banner of {s7} over the castle gate."),
        (else_try),
            (str_store_string, s11, "@ This castle has no garrison."),
        (try_end),
    (else_try),
        (try_begin),
            (eq, ":var_9", "trp_player"),
            (str_store_string, s11, "@ Your own banner flies over the town gates."),
        (else_try),
            (gt, ":var_9", -1),
            (troop_slot_eq, ":var_9", slot_troop_spouse, "trp_player"),
            (str_store_string, s11, "str__the_banner_of_your_wifehusband_s7_flies_over_the_town_gates"),
        (else_try),
            (ge, ":var_9", 0),
            (str_store_string, s11, "@ You see the banner of {s7} over the town gates."),
        (else_try),
            (str_store_string, s11, "@ This town has no garrison."),
        (try_end),
    (try_end),
    (str_clear, s12),
    (try_begin),
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (party_get_slot, ":var_14", "$current_town", slot_center_player_relation),
        (call_script, "script_describe_center_relation_to_s3", ":var_14"),
        (assign, reg9, ":var_14"),
        (str_store_string, s12, "@{!} {s3} ({reg9})."),
    (try_end),
    (str_clear, s13),
    (try_begin),
        (gt, "$entry_to_town_forbidden", 0),
        (str_store_string, s13, "@ You have successfully sneaked in."),
    (else_try),
        (faction_slot_eq, ":var_10", slot_faction_ai_state, 6),
        (faction_slot_eq, ":var_10", slot_faction_ai_object, "$current_town"),
        (str_store_string, s13, "str__the_lord_is_currently_holding_a_feast_in_his_hall"),
    (try_end),
    (try_begin),
        (store_time_of_day, reg12),
        (ge, reg12, 5),
        (neg|ge, reg12, 21),
        (assign, "$town_nighttime", 0),
    (else_try),
        (assign, "$town_nighttime", 1),
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (str_store_string, s13, "str_town_nighttime"),
    (try_end),
    (try_begin),
        (party_slot_ge, "$current_town", slot_town_has_tournament, 1),
        (neg|is_currently_night),
        (party_set_slot, "$current_town", slot_town_has_tournament, 1),
        (str_store_string, s13, "@{s13} A tournament will be held here soon."),
        (try_begin),
            (neg|troop_slot_ge, "trp_player", slot_troop_renown, 150),
            (try_begin),
                (troop_slot_ge, "trp_player", slot_troop_banner_scene_prop, 1),
                (str_store_string, s13, "@{s13} Though the heralds recognize your banner and your noble origins, the few left free spots are quickly handed out to more reknowned knights and you are not allowed to participate in this tournament."),
            (else_try),
                (str_store_string, s13, "@{s13} You have neither a noble origin nor are you renowned. Therefore you are not allowed to participate in this tournament."),
            (try_end),
        (else_try),
            (neg|troop_slot_ge, "trp_player", slot_troop_banner_scene_prop, 1),
            (str_store_string, s13, "@{s13} Despite not beeing of noble origins, the tales of your deeds in battle and your weapon prowess has spread over Pendor and reached the heralds. Therefore they allow you to join the ranks and fight in this tournament!"),
        (try_end),
    (try_end),
    (assign, "$castle_undefended", 0),
    (party_get_num_companions, ":var_15", "p_collective_enemy"),
    (try_begin),
        (eq, ":var_15", 0),
        (assign, "$castle_undefended", 1),
    (try_end),
    (call_script, "script_set_town_picture"),
],
[
    ("castle_castle", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 2),
        (eq, "$sneaked_into_town", 0),
        (str_clear, s1),
        (try_begin),
            (store_faction_of_party, ":var_0", "$current_town"),
            (faction_slot_eq, ":var_0", slot_faction_ai_state, 6),
            (faction_slot_eq, ":var_0", slot_faction_ai_object, "$current_town"),
            (str_store_string, s1, "str__join_the_feast"),
        (try_end),
    ],
    "Go to the Lord's hall{s1}.",
    [
        (try_begin),
            (this_or_next|eq, "$all_doors_locked", 1),
            (eq, "$sneaked_into_town", 1),
            (display_message, "str_door_locked", 0xFFFFAAAA),
        (else_try),
            (this_or_next|neg|eq, "$players_kingdom", "$g_encountered_party_faction"),
            (neg|troop_slot_ge, "trp_player", slot_troop_renown, 50),
            (neg|troop_slot_ge, "trp_player", slot_troop_renown, 125),
            (neg|eq, "$g_player_eligible_feast_center_no", "$current_town"),
            (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_state, 6),
            (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_object, "$g_encountered_party"),
            (neg|check_quest_active, "qst_wed_betrothed"),
            (neg|check_quest_active, "qst_wed_betrothed_female"),
            (neg|troop_slot_ge, "trp_player", slot_troop_spouse, "trp_npc_adonja"),
            (jump_to_menu, "mnu_cannot_enter_court"),
        (else_try),
            (party_get_slot, ":var_0", "$current_town", 289),
            (gt, ":var_0", 0),
            (troop_slot_eq, "trp_player", 162, ":var_0"),
            (store_troop_faction, ":var_1", ":var_0"),
            (faction_slot_eq, ":var_1", 72, 6),
            (faction_slot_ge, ":var_1", 71, 300),
            (quest_slot_eq, "qst_order_grandmaster", 11, 0),
            (quest_set_slot, "qst_order_grandmaster", 11, 1),
            (quest_set_slot, "qst_order_grandmaster", 12, "$current_town"),
            (set_jump_mission, "mt_grandmaster_ambush"),
            (party_get_slot, ":var_2", "$current_town", slot_town_castle),
            (modify_visitors_at_site, ":var_2"),
            (reset_visitors),
            (set_visitor, 0, "trp_player"),
            (set_visitor, 1, ":var_0"),
            (set_visitor, 2, ":var_0"),
            (set_visitor, 3, "trp_snake_priestess"),
            (set_visitor, 4, "trp_anaconda_knight"),
            (set_visitor, 5, "trp_anaconda_knight"),
            (set_visitor, 6, "trp_cobra_warrior"),
            (set_visitor, 7, "trp_cobra_warrior"),
            (jump_to_scene, ":var_2"),
            (scene_set_slot, ":var_2", 0, 1),
            (change_screen_mission),
        (else_try),
            (assign, "$town_entered", 1),
            (call_script, "script_enter_court", "$current_town"),
        (try_end),
    ], "Door to the castle."),

    ("join_tournament", 
    [
        (neg|is_currently_night),
        (party_slot_ge, "$current_town", slot_town_has_tournament, 1),
        (troop_slot_ge, "trp_player", slot_troop_renown, 150),
    ],
    "Join the tournament.",
    [
        (call_script, "script_fill_tournament_participants_troop", "$current_town", 1),
        (assign, "$g_tournament_cur_tier", 0),
        (assign, "$g_tournament_player_team_won", -1),
        (assign, "$g_tournament_bet_placed", 0),
        (assign, "$g_tournament_bet_win_amount", 0),
        (assign, "$g_tournament_last_bet_tier", -1),
        (assign, "$g_tournament_next_num_teams", 0),
        (assign, "$g_tournament_next_team_size", 0),
        (jump_to_menu, "mnu_town_tournament"),
    ], "."),

    ("town_castle", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (eq, "$entry_to_town_forbidden", 0),
        (str_clear, s1),
        (try_begin),
            (store_faction_of_party, ":var_0", "$current_town"),
            (faction_slot_eq, ":var_0", slot_faction_ai_state, 6),
            (faction_slot_eq, ":var_0", slot_faction_ai_object, "$current_town"),
            (str_store_string, s1, "str__join_the_feast"),
        (try_end),
    ],
    "Go to the castle{s1}.",
    [
        (try_begin),
            (this_or_next|eq, "$all_doors_locked", 1),
            (eq, "$sneaked_into_town", 1),
            (display_message, "str_door_locked", 0xFFFFAAAA),
        (else_try),
            (this_or_next|neg|eq, "$players_kingdom", "$g_encountered_party_faction"),
            (neg|troop_slot_ge, "trp_player", slot_troop_renown, 50),
            (neg|troop_slot_ge, "trp_player", slot_troop_renown, 125),
            (neg|eq, "$g_player_eligible_feast_center_no", "$current_town"),
            (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_state, 6),
            (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_object, "$g_encountered_party"),
            (neg|check_quest_active, "qst_wed_betrothed"),
            (neg|check_quest_active, "qst_wed_betrothed_female"),
            (neg|troop_slot_ge, "trp_player", slot_troop_spouse, "trp_npc_adonja"),
            (jump_to_menu, "mnu_cannot_enter_court"),
        (else_try),
            (party_get_slot, ":var_0", "$current_town", 289),
            (gt, ":var_0", 0),
            (troop_slot_eq, "trp_player", 162, ":var_0"),
            (store_troop_faction, ":var_1", ":var_0"),
            (faction_slot_eq, ":var_1", 72, 6),
            (faction_slot_ge, ":var_1", 71, 300),
            (quest_slot_eq, "qst_order_grandmaster", 11, 0),
            (quest_set_slot, "qst_order_grandmaster", 11, 1),
            (quest_set_slot, "qst_order_grandmaster", 12, "$current_town"),
            (set_jump_mission, "mt_grandmaster_ambush"),
            (party_get_slot, ":var_2", "$current_town", slot_town_castle),
            (modify_visitors_at_site, ":var_2"),
            (reset_visitors),
            (set_visitor, 0, "trp_player"),
            (set_visitor, 1, ":var_0"),
            (set_visitor, 2, ":var_0"),
            (set_visitor, 3, "trp_snake_priestess"),
            (set_visitor, 4, "trp_anaconda_knight"),
            (set_visitor, 5, "trp_anaconda_knight"),
            (set_visitor, 6, "trp_cobra_warrior"),
            (set_visitor, 7, "trp_cobra_warrior"),
            (jump_to_scene, ":var_2"),
            (scene_set_slot, ":var_2", 0, 1),
            (change_screen_mission),
        (else_try),
            (assign, "$town_entered", 1),
            (call_script, "script_enter_court", "$current_town"),
        (try_end),
    ], "Door to the castle."),

    ("town_center", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (this_or_next|eq, "$entry_to_town_forbidden", 0),
        (eq, "$sneaked_into_town", 1),
    ],
    "Take a walk around the streets.",
    [
        (try_begin),
            (eq, "$talk_context", 18),
            (assign, "$talk_context", 19),
            (assign, "$g_mt_mode", 3),
            (store_faction_of_party, ":var_0", "$current_town"),
            (faction_get_slot, ":var_1", ":var_0", slot_faction_quick_battle_tier_1_archer),
            (faction_get_slot, ":var_2", ":var_0", slot_faction_quick_battle_tier_1_archer),
            (faction_get_slot, ":var_3", ":var_0", slot_faction_quick_battle_tier_2_archer),
            (party_get_slot, ":var_4", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_4"),
            (reset_visitors),
            (try_begin),
                (party_get_slot, ":var_5", "$current_town", slot_town_last_nearby_fire_time),
                (store_current_hours, ":var_6"),
                (store_add, ":var_7", ":var_5", 4),
                (neg|is_between, ":var_6", ":var_5", ":var_7"),
                (store_time_of_day, ":var_8"),
                (try_begin),
                    (ge, ":var_8", 6),
                    (neg|ge, ":var_8", 22),
                    (set_visitors, 25, ":var_1", 2),
                    (set_visitors, 26, ":var_1", 1),
                    (set_visitors, 27, ":var_2", 2),
                    (set_visitors, 28, ":var_3", 1),
                (else_try),
                    (set_visitors, 25, ":var_1", 1),
                    (set_visitors, 26, ":var_1", 1),
                    (set_visitors, 27, ":var_2", 1),
                    (set_visitors, 28, ":var_3", 1),
                (try_end),
            (else_try),
                (store_time_of_day, ":var_8"),
                (try_begin),
                    (ge, ":var_8", 6),
                    (neg|ge, ":var_8", 22),
                    (set_visitors, 25, ":var_1", 1),
                    (set_visitors, 26, ":var_1", 0),
                    (set_visitors, 27, ":var_2", 1),
                    (set_visitors, 28, ":var_3", 0),
                (else_try),
                    (set_visitors, 25, ":var_1", 1),
                    (set_visitors, 26, ":var_1", 0),
                    (set_visitors, 27, ":var_2", 0),
                    (set_visitors, 28, ":var_3", 0),
                (try_end),
            (try_end),
            (set_jump_mission, "mt_town_center"),
            (jump_to_scene, ":var_4"),
            (change_screen_mission),
        (else_try),
            (assign, "$talk_context", 0),
            (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
            (party_get_slot, ":var_4", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_4"),
            (reset_visitors),
            (assign, "$g_mt_mode", 0),
            (store_faction_of_party, ":var_0", "$current_town"),
            (try_begin),
                (neg|eq, ":var_0", "fac_player_supporters_faction"),
                (faction_get_slot, ":var_9", "$g_encountered_party_faction", slot_faction_prison_guard_troop),
                (faction_get_slot, ":var_10", "$g_encountered_party_faction", slot_faction_castle_guard_troop),
                (faction_get_slot, ":var_1", ":var_0", slot_faction_quick_battle_tier_2_infantry),
                (faction_get_slot, ":var_2", ":var_0", slot_faction_quick_battle_tier_1_archer),
            (else_try),
                (party_get_slot, ":var_11", "$current_town", slot_center_original_faction),
                (faction_get_slot, ":var_9", ":var_11", slot_faction_prison_guard_troop),
                (faction_get_slot, ":var_10", ":var_11", slot_faction_castle_guard_troop),
                (faction_get_slot, ":var_1", ":var_11", slot_faction_quick_battle_tier_2_infantry),
                (faction_get_slot, ":var_2", ":var_11", slot_faction_quick_battle_tier_1_archer),
            (try_end),
            (try_begin),
                (party_get_slot, ":var_5", "$current_town", slot_town_last_nearby_fire_time),
                (store_current_hours, ":var_6"),
                (store_add, ":var_7", ":var_5", 4),
                (neg|is_between, ":var_6", ":var_5", ":var_7"),
                (set_visitor, 23, ":var_10"),
            (try_end),
            (set_visitor, 24, ":var_9"),
            (try_begin),
                (gt, ":var_1", 0),
                (assign, reg0, ":var_2"),
                (assign, reg1, ":var_2"),
                (assign, reg2, ":var_1"),
                (assign, reg3, ":var_1"),
            (else_try),
                (assign, reg0, "trp_rav_footman"),
                (assign, reg1, "trp_rav_footman"),
                (assign, reg2, "trp_rav_archer"),
                (assign, reg3, "trp_rav_militia"),
            (try_end),
            (shuffle_range, 0, 4),
            (try_begin),
                (party_get_slot, ":var_5", "$current_town", slot_town_last_nearby_fire_time),
                (store_current_hours, ":var_6"),
                (store_add, ":var_7", ":var_5", 4),
                (neg|is_between, ":var_6", ":var_5", ":var_7"),
                (set_visitor, 25, reg0),
                (set_visitor, 26, reg1),
                (set_visitor, 27, reg2),
                (set_visitor, 28, reg3),
            (try_end),
            (party_get_slot, ":var_12", "$current_town", slot_town_armorer),
            (set_visitor, 9, ":var_12"),
            (party_get_slot, ":var_12", "$current_town", slot_town_weaponsmith),
            (set_visitor, 10, ":var_12"),
            (party_get_slot, ":var_12", "$current_town", slot_town_elder),
            (set_visitor, 11, ":var_12"),
            (party_get_slot, ":var_12", "$current_town", slot_town_horse_merchant),
            (set_visitor, 12, ":var_12"),
            (call_script, "script_init_town_walkers"),
            (set_jump_mission, "mt_town_center"),
            (assign, ":var_13", 256),
            (try_begin),
                (eq, "$sneaked_into_town", 1),
                (assign, ":var_13", 447),
            (try_end),
            (mission_tpl_entry_set_override_flags, "mt_town_center", 0, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_town_center", 2, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_town_center", 3, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_town_center", 4, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_town_center", 5, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_town_center", 6, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_town_center", 7, ":var_13"),
            (try_begin),
                (eq, "$town_entered", 0),
                (assign, "$town_entered", 1),
                (eq, "$town_nighttime", 0),
                (set_jump_entry, 1),
            (try_end),
            (jump_to_scene, ":var_4"),
            (change_screen_mission),
        (try_end),
    ], "Door to the town center."),

    ("town_tavern", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (this_or_next|eq, "$entry_to_town_forbidden", 0),
        (eq, "$sneaked_into_town", 1),
    ],
    "Visit the tavern.",
    [
        (try_begin),
            (eq, "$all_doors_locked", 1),
            (display_message, "str_door_locked", 0xFFFFAAAA),
        (else_try),
            (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
            (assign, "$town_entered", 1),
            (set_jump_mission, "mt_town_default"),
            (mission_tpl_entry_set_override_flags, "mt_town_default", 0, 256),
            (try_begin),
                (eq, "$sneaked_into_town", 1),
                (mission_tpl_entry_set_override_flags, "mt_town_default", 0, 447),
            (try_end),
            (party_get_slot, ":var_0", "$current_town", slot_town_tavern),
            (jump_to_scene, ":var_0"),
            (scene_set_slot, ":var_0", 0, 1),
            (assign, "$talk_context", 14),
            (call_script, "script_initialize_tavern_variables"),
            (store_random_in_range, ":var_1", 0, 4),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (assign, ":var_2", 17),
            (try_begin),
                (eq, "$cheat_mode", 1),
                (troop_get_slot, ":var_3", "trp_belligerent_drunk", slot_troop_cur_center),
                (try_begin),
                    (eq, "$cheat_mode", 0),
                (else_try),
                    (is_between, ":var_3", "p_town_1", "p_salt_mine"),
                    (str_store_party_name, s4, ":var_3"),
                    (display_message, "str_belligerent_drunk_in_s4"),
                (else_try),
                    (display_message, "str_belligerent_drunk_not_found"),
                (try_end),
                (troop_get_slot, ":var_4", "trp_fight_promoter", slot_troop_cur_center),
                (try_begin),
                    (eq, "$cheat_mode", 0),
                (else_try),
                    (is_between, ":var_4", "p_town_1", "p_salt_mine"),
                    (str_store_party_name, s4, ":var_4"),
                    (display_message, "str_roughlooking_character_in_s4"),
                (else_try),
                    (display_message, "str_roughlooking_character_not_found"),
                (try_end),
            (try_end),
            (try_begin),
                (store_current_hours, ":var_5"),
                (store_sub, ":var_6", ":var_5", "$g_last_assassination_attempt_time"),
                (gt, ":var_6", 168),
                (try_for_range, ":var_7", "trp_npc_adonja", "trp_knight_1_1_wife"),
                    (troop_slot_eq, ":var_7", slot_lord_reputation_type, 5),
                    (troop_get_slot, ":var_8", ":var_7", slot_troop_leaded_party),
                    (party_is_active, ":var_8"),
                    (party_get_attached_to, ":var_9", ":var_8"),
                    (eq, ":var_9", "$g_encountered_party"),
                    (call_script, "script_troop_get_relation_with_troop", "trp_player", ":var_7"),
                    (neg|ge, reg0, -20),
                    (assign, "$g_last_assassination_attempt_time", ":var_5"),
                    (troop_set_slot, "trp_hired_assassin", slot_troop_cur_center, "$g_encountered_party"),
                (try_end),
            (try_end),
            (try_begin),
                (eq, ":var_1", 0),
                (call_script, "script_setup_tavern_attacker", ":var_2"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (eq, 1, 0),
                (troop_slot_eq, "trp_fight_promoter", slot_troop_cur_center, "$current_town"),
                (set_visitor, ":var_2", "trp_fight_promoter"),
                (val_add, ":var_2", 1),
            (try_end),
            (party_get_slot, ":var_10", "$current_town", slot_center_npc_volunteer_troop_type),
            (party_get_slot, ":var_11", "$current_town", slot_center_npc_volunteer_troop_amount),
            (try_begin),
                (gt, ":var_10", 0),
                (gt, ":var_11", 0),
                (set_visitor, ":var_2", ":var_10"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (eq, ":var_1", 1),
                (call_script, "script_setup_tavern_attacker", ":var_2"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_for_range, ":var_12", "trp_npc_adonja", "trp_kingdom_1_lord"),
                (troop_slot_eq, ":var_12", slot_troop_occupation, 0),
                (troop_slot_eq, ":var_12", slot_troop_cur_center, "$current_town"),
                (neg|troop_slot_ge, ":var_12", slot_troop_prisoner_of_party, "p_town_1"),
                (set_visitor, ":var_2", ":var_12"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (eq, ":var_1", 2),
                (call_script, "script_setup_tavern_attacker", ":var_2"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (party_get_slot, ":var_13", "$current_town", slot_center_ransom_broker),
                (gt, ":var_13", 0),
                (assign, reg0, ":var_13"),
                (assign, reg1, "$current_town"),
                (set_visitor, ":var_2", ":var_13"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (party_get_slot, ":var_14", "$current_town", slot_center_tavern_traveler),
                (gt, ":var_14", 0),
                (set_visitor, ":var_2", ":var_14"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (party_get_slot, ":var_15", "$current_town", slot_center_tavern_minstrel),
                (gt, ":var_15", 0),
                (set_visitor, ":var_2", ":var_15"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (party_get_slot, ":var_16", "$current_town", slot_center_tavern_bookseller),
                (gt, ":var_16", 0),
                (set_visitor, ":var_2", ":var_16"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (eq, ":var_1", 3),
                (call_script, "script_setup_tavern_attacker", ":var_2"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (neg|check_quest_active, "qst_eliminate_bandits_infesting_village"),
                (neg|check_quest_active, "qst_deal_with_bandits_at_lords_village"),
                (assign, ":var_17", "p_salt_mine"),
                (try_for_range, ":var_18", "p_village_1", ":var_17"),
                    (party_slot_eq, ":var_18", slot_village_bound_center, "$current_town"),
                    (party_slot_ge, ":var_18", slot_village_infested_by_bandits, 1),
                    (neg|party_slot_eq, ":var_18", slot_town_lord, "trp_player"),
                    (set_visitor, ":var_2", "trp_farmer_from_bandit_village"),
                    (val_add, ":var_2", 1),
                    (assign, ":var_17", 0),
                (try_end),
            (try_end),
            (try_begin),
                (eq, "$g_starting_town", "$current_town"),
                (this_or_next|neg|check_quest_finished, "qst_collect_men"),
                (this_or_next|neg|check_quest_finished, "qst_learn_where_merchant_brother_is"),
                (this_or_next|neg|check_quest_finished, "qst_save_relative_of_merchant"),
                (eq, "$g_do_one_more_meeting_with_merchant", 1),
                (assign, ":var_19", 0),
                (try_begin),
                    (eq, "$g_encountered_party_faction", "fac_kingdom_1"),
                    (assign, ":var_19", "trp_sarleon_merchant"),
                (else_try),
                    (eq, "$g_encountered_party_faction", "fac_kingdom_2"),
                    (assign, ":var_19", "trp_ravenstern_merchant"),
                (else_try),
                    (eq, "$g_encountered_party_faction", "fac_kingdom_3"),
                    (assign, ":var_19", "trp_dshar_merchant"),
                (else_try),
                    (eq, "$g_encountered_party_faction", "fac_kingdom_4"),
                    (assign, ":var_19", "trp_fierdsvain_merchant"),
                (else_try),
                    (eq, "$g_encountered_party_faction", "fac_kingdom_5"),
                    (assign, ":var_19", "trp_empire_merchant"),
                (try_end),
                (gt, ":var_19", 0),
                (set_visitor, ":var_2", ":var_19"),
                (val_add, ":var_2", 1),
            (try_end),
            (try_begin),
                (store_random_in_range, ":var_20", 0, 100),
                (neg|ge, ":var_20", 5),
                (store_random_in_range, ":var_20", 0, 9),
                (try_begin),
                    (eq, ":var_20", 0),
                    (assign, ":var_21", "trp_radiant_cross_knight"),
                (else_try),
                    (eq, ":var_20", 1),
                    (assign, ":var_21", "trp_raven_spear_knight"),
                (else_try),
                    (eq, ":var_20", 2),
                    (assign, ":var_21", "trp_ebony_gauntlet"),
                (else_try),
                    (eq, ":var_20", 3),
                    (assign, ":var_21", "trp_eventide_knight"),
                (else_try),
                    (eq, ":var_20", 4),
                    (assign, ":var_21", "trp_shadow_centurion"),
                (else_try),
                    (eq, ":var_20", 5),
                    (assign, ":var_21", "trp_dawn_knight"),
                (else_try),
                    (eq, ":var_20", 6),
                    (assign, ":var_21", "trp_silvermist_ranger"),
                (else_try),
                    (eq, ":var_20", 7),
                    (assign, ":var_21", "trp_clarion_ranger"),
                (else_try),
                    (assign, ":var_21", "trp_falcon_knight"),
                (try_end),
                (set_visitor, ":var_2", ":var_21"),
                (val_add, ":var_2", 1),
            (try_end),
            (change_screen_mission),
        (try_end),
    ], "Door to the tavern."),

    ("town_merchant", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (eq, 1, 0),
        (eq, "$town_nighttime", 0),
        (this_or_next|eq, "$entry_to_town_forbidden", 0),
        (eq, "$sneaked_into_town", 1),
    ],
    "Speak with the merchant.",
    [
        (try_begin),
            (this_or_next|eq, "$all_doors_locked", 1),
            (eq, "$town_nighttime", 1),
            (display_message, "str_door_locked", 0xFFFFAAAA),
        (else_try),
            (assign, "$town_entered", 1),
            (set_jump_mission, "mt_town_default"),
            (mission_tpl_entry_set_override_flags, "mt_town_default", 0, 256),
            (try_begin),
                (eq, "$sneaked_into_town", 1),
                (mission_tpl_entry_set_override_flags, "mt_town_default", 0, 447),
            (try_end),
            (party_get_slot, ":var_0", "$current_town", slot_town_store),
            (jump_to_scene, ":var_0"),
            (scene_set_slot, ":var_0", 0, 1),
            (change_screen_mission),
        (try_end),
    ], "Door to the shop."),

    ("town_arena", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (eq, "$sneaked_into_town", 0),
    ],
    "Enter the arena.",
    [
        (try_begin),
            (this_or_next|eq, "$all_doors_locked", 1),
            (eq, "$town_nighttime", 1),
            (display_message, "str_door_locked", 0xFFFFAAAA),
        (else_try),
            (assign, "$g_mt_mode", 2),
            (assign, "$town_entered", 1),
            (set_jump_mission, "mt_arena_melee_fight"),
            (party_get_slot, ":var_0", "$current_town", slot_town_arena),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (set_visitor, 43, "trp_veteran_fighter"),
            (set_visitor, 44, "trp_hired_blade"),
            (set_jump_entry, 50),
            (jump_to_scene, ":var_0"),
            (scene_set_slot, ":var_0", 0, 1),
            (change_screen_mission),
        (try_end),
    ], "Door to the arena."),

    ("town_dungeon", 
    [
        (eq, 1, 0),
    ],
    "Never: Enter the prison.",
    [
        (try_begin),
            (eq, "$talk_context", 18),
            (gt, "$g_main_attacker_agent", 0),
            (neg|agent_is_alive, "$g_main_attacker_agent"),
            (agent_get_troop_id, ":var_0", "$g_main_attacker_agent"),
            (try_begin),
                (eq, "$g_encountered_party_faction", "fac_player_supporters_faction"),
                (party_get_slot, ":var_1", "$current_town", slot_center_original_faction),
            (else_try),
                (assign, ":var_1", "$g_encountered_party_faction"),
            (try_end),
            (faction_slot_eq, ":var_1", slot_faction_prison_guard_troop, ":var_0"),
            (call_script, "script_deduct_casualties_from_garrison"),
            (call_script, "script_enter_dungeon", "$current_town", "mt_visit_town_castle"),
        (else_try),
            (eq, "$all_doors_locked", 1),
            (display_message, "str_door_locked", 0xFFFFAAAA),
        (else_try),
            (this_or_next|party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
            (eq, "$g_encountered_party_faction", "$players_kingdom"),
            (assign, "$town_entered", 1),
            (call_script, "script_enter_dungeon", "$current_town", "mt_visit_town_castle"),
        (else_try),
            (display_message, "str_door_locked", 0xFFFFAAAA),
        (try_end),
    ], "Door to the dungeon."),

    ("castle_inspect", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 2),
    ],
    "Take a walk around the courtyard.",
    [
        (try_begin),
            (eq, "$talk_context", 18),
            (assign, "$talk_context", 19),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (assign, ":var_1", 40),
            (party_get_num_companion_stacks, ":var_2", "$g_encountered_party"),
            (try_for_range, ":var_3", 0, ":var_2"),
                (party_get_slot, ":var_4", "$current_town", slot_town_last_nearby_fire_time),
                (store_current_hours, ":var_5"),
                (store_add, ":var_6", ":var_4", 4),
                (this_or_next|eq, ":var_1", 40),
                (neg|is_between, ":var_5", ":var_4", ":var_6"),
                (neg|ge, ":var_1", 47),
                (party_stack_get_troop_id, ":var_7", "$g_encountered_party", ":var_3"),
                (neg|troop_is_hero, ":var_7"),
                (party_stack_get_size, ":var_8", "$g_encountered_party", ":var_3"),
                (party_stack_get_num_wounded, ":var_9", "$g_encountered_party", ":var_3"),
                (val_sub, ":var_8", ":var_9"),
                (gt, ":var_8", 0),
                (party_stack_get_troop_dna, ":var_10", "$g_encountered_party", ":var_3"),
                (set_visitor, ":var_1", ":var_7", ":var_10"),
                (val_add, ":var_1", 1),
            (try_end),
            (set_visitor, 7, "$g_player_troop"),
            (set_jump_mission, "mt_castle_visit"),
            (jump_to_scene, ":var_0"),
            (change_screen_mission),
        (else_try),
            (assign, "$talk_context", 0),
            (assign, "$g_mt_mode", 0),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
            (modify_visitors_at_site, ":var_0"),
            (reset_visitors),
            (try_begin),
                (neg|eq, "$g_encountered_party_faction", "fac_player_supporters_faction"),
                (faction_get_slot, ":var_11", "$g_encountered_party_faction", slot_faction_prison_guard_troop),
            (else_try),
                (party_get_slot, ":var_12", "$current_town", slot_center_original_faction),
                (faction_get_slot, ":var_11", ":var_12", slot_faction_prison_guard_troop),
            (try_end),
            (set_visitor, 24, ":var_11"),
            (assign, ":var_1", 40),
            (party_get_num_companion_stacks, ":var_2", "$g_encountered_party"),
            (try_for_range, ":var_3", 0, ":var_2"),
                (party_get_slot, ":var_4", "$current_town", slot_town_last_nearby_fire_time),
                (store_current_hours, ":var_5"),
                (store_add, ":var_6", ":var_4", 4),
                (neg|is_between, ":var_5", ":var_6", ":var_4"),
                (neg|ge, ":var_1", 47),
                (party_stack_get_troop_id, ":var_7", "$g_encountered_party", ":var_3"),
                (neg|troop_is_hero, ":var_7"),
                (party_stack_get_size, ":var_8", "$g_encountered_party", ":var_3"),
                (party_stack_get_num_wounded, ":var_9", "$g_encountered_party", ":var_3"),
                (val_sub, ":var_8", ":var_9"),
                (gt, ":var_8", 0),
                (party_stack_get_troop_dna, ":var_10", "$g_encountered_party", ":var_3"),
                (set_visitor, ":var_1", ":var_7", ":var_10"),
                (val_add, ":var_1", 1),
            (try_end),
            (try_begin),
                (eq, "$town_entered", 0),
                (assign, "$town_entered", 1),
            (try_end),
            (set_jump_entry, 1),
            (assign, ":var_13", 256),
            (try_begin),
                (eq, "$sneaked_into_town", 1),
                (assign, ":var_13", 447),
            (try_end),
            (set_jump_mission, "mt_castle_visit"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 0, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 1, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 2, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 3, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 4, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 5, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 6, ":var_13"),
            (mission_tpl_entry_set_override_flags, "mt_castle_visit", 7, ":var_13"),
            (jump_to_scene, ":var_0"),
            (change_screen_mission),
        (try_end),
    ], "To the castle courtyard."),

    ("town_enterprise", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (party_get_slot, ":var_0", "$current_town", slot_center_player_enterprise),
        (gt, ":var_0", 1),
        (eq, "$entry_to_town_forbidden", 0),
        (call_script, "script_get_enterprise_name", ":var_0"),
        (str_store_string, s3, reg0),
    ],
    "Visit your {s3}.",
    [
        (store_sub, ":var_0", "$current_town", "p_town_1"),
        (store_add, ":var_1", "trp_town_1_master_craftsman", ":var_0"),
        (party_get_slot, ":var_2", "$current_town", slot_center_player_enterprise),
        (assign, ":var_3", "scn_enterprise_mill"),
        (try_begin),
            (eq, ":var_2", "itm_bread"),
            (assign, ":var_3", "scn_enterprise_mill"),
        (else_try),
            (eq, ":var_2", "itm_ale"),
            (assign, ":var_3", "scn_enterprise_brewery"),
        (else_try),
            (eq, ":var_2", "itm_oil"),
            (assign, ":var_3", "scn_enterprise_oil_press"),
        (else_try),
            (eq, ":var_2", "itm_wine"),
            (assign, ":var_3", "scn_enterprise_winery"),
        (else_try),
            (eq, ":var_2", "itm_leatherwork"),
            (assign, ":var_3", "scn_enterprise_tannery"),
        (else_try),
            (eq, ":var_2", "itm_wool_cloth"),
            (assign, ":var_3", "scn_enterprise_wool_weavery"),
        (else_try),
            (eq, ":var_2", "itm_linen"),
            (assign, ":var_3", "scn_enterprise_linen_weavery"),
        (else_try),
            (eq, ":var_2", "itm_velvet"),
            (assign, ":var_3", "scn_enterprise_dyeworks"),
        (else_try),
            (eq, ":var_2", "itm_tools"),
            (assign, ":var_3", "scn_enterprise_smithy"),
        (try_end),
        (modify_visitors_at_site, ":var_3"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 17, ":var_1"),
        (set_jump_mission, "mt_town_default"),
        (jump_to_scene, ":var_3"),
        (change_screen_mission),
    ], "Door to your enterprise."),

    ("visit_lady", 
    [
        (neg|troop_slot_ge, "trp_player", slot_troop_spouse, "trp_knight_1_1_wife"),
        (assign, "$love_interest_in_town", 0),
        (assign, "$love_interest_in_town_2", 0),
        (assign, "$love_interest_in_town_3", 0),
        (assign, "$love_interest_in_town_4", 0),
        (assign, "$love_interest_in_town_5", 0),
        (assign, "$love_interest_in_town_6", 0),
        (assign, "$love_interest_in_town_7", 0),
        (assign, "$love_interest_in_town_8", 0),
        (try_for_range, ":var_0", "trp_knight_1_1_wife", "trp_heroes_end"),
            (troop_slot_eq, ":var_0", slot_troop_cur_center, "$current_town"),
            (call_script, "script_get_kingdom_lady_social_determinants", ":var_0"),
            (assign, ":var_1", reg0),
            (troop_slot_eq, ":var_0", slot_troop_spouse, -1),
            (ge, ":var_1", 0),
            (this_or_next|troop_slot_ge, ":var_0", slot_troop_met, 2),
            (troop_slot_eq, ":var_1", slot_troop_love_interests_end, 1),
            (neg|troop_slot_eq, ":var_0", slot_troop_met, 4),
            (try_begin),
                (eq, "$love_interest_in_town", 0),
                (assign, "$love_interest_in_town", ":var_0"),
            (else_try),
                (eq, "$love_interest_in_town_2", 0),
                (assign, "$love_interest_in_town_2", ":var_0"),
            (else_try),
                (eq, "$love_interest_in_town_3", 0),
                (assign, "$love_interest_in_town_3", ":var_0"),
            (else_try),
                (eq, "$love_interest_in_town_4", 0),
                (assign, "$love_interest_in_town_4", ":var_0"),
            (else_try),
                (eq, "$love_interest_in_town_5", 0),
                (assign, "$love_interest_in_town_5", ":var_0"),
            (else_try),
                (eq, "$love_interest_in_town_6", 0),
                (assign, "$love_interest_in_town_6", ":var_0"),
            (else_try),
                (eq, "$love_interest_in_town_7", 0),
                (assign, "$love_interest_in_town_7", ":var_0"),
            (else_try),
                (eq, "$love_interest_in_town_8", 0),
                (assign, "$love_interest_in_town_8", ":var_0"),
            (try_end),
        (try_end),
        (gt, "$love_interest_in_town", 0),
    ],
    "Attempt to visit a lady",
    [
        (jump_to_menu, "mnu_lady_visit"),
    ], "Door to the garden."),

    ("trade_with_merchants", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
    ],
    "Go to the marketplace.",
    [
        (try_begin),
            (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
            (jump_to_menu, "mnu_town_trade"),
        (try_end),
    ], "."),

    ("guildmaster_talk", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
    ],
    "Speak with the Guildmaster.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_center),
        (modify_visitors_at_site, ":var_0"),
        (reset_visitors),
        (party_get_slot, ":var_1", "$current_town", slot_town_elder),
        (set_visitor, 11, ":var_1"),
        (call_script, "script_init_town_walkers"),
        (set_jump_mission, "mt_town_center"),
        (jump_to_scene, ":var_0"),
        (change_screen_map_conversation, ":var_1"),
    ], "."),

    ("walled_center_manage", 
    [
        (neg|party_slot_eq, "$current_town", slot_village_state, 5),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
        (assign, reg0, 1),
        (try_begin),
            (party_slot_eq, "$current_town", slot_party_type, 2),
            (assign, reg0, 0),
        (try_end),
    ],
    "Manage this {reg0?town:castle}.",
    [
        (assign, "$g_next_menu", "mnu_town"),
        (jump_to_menu, "mnu_center_manage"),
    ], "."),

    ("walled_center_train_steward", 
    [
        (neg|party_slot_eq, "$current_town", slot_village_state, 5),
        (party_slot_eq, "$current_town", 295, 1),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
        (assign, reg0, 1),
        (try_begin),
            (party_slot_eq, "$current_town", slot_party_type, 2),
            (assign, reg0, 0),
        (try_end),
    ],
    "Train your {reg0?town:castle} steward.",
    [
        (assign, "$g_next_menu", "mnu_town"),
        (jump_to_menu, "mnu_steward_training"),
    ], "."),

    ("walled_center_move_court", 
    [
        (neg|party_slot_eq, "$current_town", slot_village_state, 5),
        (faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
        (eq, "$g_encountered_party_faction", "fac_player_supporters_faction"),
        (neg|eq, "$g_player_court", "$current_town"),
    ],
    "Move your court here.",
    [
        (jump_to_menu, "mnu_establish_court"),
    ], "."),

    ("castle_station_troops", 
    [
        (neg|check_quest_active, "qst_order_challenge"),
        (party_get_slot, ":var_0", "$current_town", slot_town_lord),
        (str_clear, s10),
        (assign, ":var_1", 0),
        (try_begin),
            (eq, ":var_0", "trp_player"),
            (assign, ":var_1", 1),
        (else_try),
            (store_faction_of_party, ":var_2", "$g_encountered_party"),
            (eq, ":var_2", "fac_player_supporters_faction"),
            (neg|party_slot_ge, "$g_encountered_party", slot_town_lord, "trp_npc_adonja"),
            (assign, ":var_1", 1),
        (else_try),
            (neg|ge, ":var_0", 0),
            (store_faction_of_party, ":var_3", "$g_encountered_party"),
            (eq, "$players_kingdom", ":var_3"),
            (eq, "$g_encountered_party", "$g_castle_requested_by_player"),
            (str_store_string, s10, "str_retrieve_garrison_warning"),
            (assign, ":var_1", 1),
        (else_try),
            (neg|ge, ":var_0", 0),
            (store_faction_of_party, ":var_3", "$g_encountered_party"),
            (eq, "$players_kingdom", ":var_3"),
            (store_party_size_wo_prisoners, ":var_4", "$g_encountered_party"),
            (eq, ":var_4", 0),
            (str_store_string, s10, "str_retrieve_garrison_warning"),
            (assign, ":var_1", 1),
        (else_try),
            (party_slot_ge, "$g_encountered_party", slot_town_lord, "trp_npc_adonja"),
            (store_faction_of_party, ":var_3", "$g_encountered_party"),
            (eq, "$players_kingdom", ":var_3"),
            (troop_slot_eq, "trp_player", slot_troop_spouse, ":var_0"),
            (assign, ":var_1", 1),
        (try_end),
        (eq, ":var_1", 1),
    ],
    "Manage the garrison. {s10}",
    [
        (change_screen_exchange_members, 1),
    ], "."),

    ("castle_wait", 
    [
        (this_or_next|ge, "$g_encountered_party_relation", 0),
        (eq, "$castle_undefended", 1),
        (assign, ":var_0", 1),
        (str_clear, s1),
        (try_begin),
            (neg|party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
            (troop_get_slot, ":var_1", "trp_player", slot_troop_spouse),
            (neg|party_slot_eq, "$current_town", slot_town_lord, ":var_1"),
            (party_slot_ge, "$current_town", slot_town_lord, "trp_player"),
            (store_faction_of_party, ":var_2", "$current_town"),
            (neg|eq, ":var_2", "fac_player_supporters_faction"),
            (party_get_num_companions, ":var_3", "p_main_party"),
            (store_div, reg1, ":var_3", 4),
            (val_add, reg1, 1),
            (str_store_string, s1, "@ ({reg1} denars per night)"),
            (store_troop_gold, ":var_4", "trp_player"),
            (neg|ge, ":var_4", reg1),
            (assign, ":var_0", 0),
        (try_end),
        (eq, ":var_0", 1),
    ],
    "Wait here for some time{s1}.",
    [
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_town_visit_after_rest", 1),
        (assign, "$g_last_rest_center", "$current_town"),
        (assign, "$g_last_rest_payment_until", -1),
        (try_begin),
            (party_is_active, "p_main_party"),
            (party_get_current_terrain, ":var_0", "p_main_party"),
            (try_begin),
                (eq, ":var_0", 5),
                (unlock_achievement, 28),
            (try_end),
        (try_end),
        (rest_for_hours_interactive, 168, 5, 0),
        (change_screen_return),
    ], "."),

    ("town_alley", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT: Go to the alley.",
    [
        (party_get_slot, reg11, "$current_town", slot_town_alley),
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, reg11),
        (change_screen_mission),
    ], "."),

    ("collect_taxes_qst", 
    [
        (check_quest_active, "qst_collect_taxes"),
        (quest_slot_eq, "qst_collect_taxes", 1, "$current_town"),
        (neg|quest_slot_eq, "qst_collect_taxes", 11, 4),
        (quest_get_slot, ":var_0", "qst_collect_taxes", 6),
        (str_store_troop_name, s1, ":var_0"),
        (quest_get_slot, reg5, "qst_collect_taxes", 11),
    ],
    "{reg5?Continue collecting taxes:Collect taxes} due to {s1}.",
    [
        (jump_to_menu, "mnu_collect_taxes"),
    ], "."),

    ("town_leave", [],
    "Leave...",
    [
        (assign, "$g_permitted_to_center", 0),
        (change_screen_return, 0),
    ], "Leave Area."),

    ("castle_cheat_interior", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! Interior.",
    [
        (set_jump_mission, "mt_ai_training"),
        (party_get_slot, ":var_0", "$current_town", slot_town_castle),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("castle_cheat_town_exterior", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! Exterior.",
    [
        (try_begin),
            (party_slot_eq, "$current_town", slot_party_type, 2),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
        (else_try),
            (party_get_slot, ":var_0", "$current_town", slot_town_center),
        (try_end),
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("castle_cheat_dungeon", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! Prison.",
    [
        (set_jump_mission, "mt_ai_training"),
        (party_get_slot, ":var_0", "$current_town", slot_town_prison),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("castle_cheat_town_walls", 
    [
        (eq, "$cheat_mode", 1),
        (party_slot_eq, "$current_town", slot_party_type, 3),
    ],
    "{!}CHEAT! Town Walls.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_walls),
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("cheat_town_start_siege", 
    [
        (eq, "$cheat_mode", 1),
        (party_slot_eq, "$g_encountered_party", slot_center_is_besieged_by, -1),
        (neg|ge, "$g_encountered_party_2", 1),
        (call_script, "script_party_count_fit_for_battle", "p_main_party"),
        (gt, reg0, 1),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 3),
            (assign, reg6, 1),
        (else_try),
            (assign, reg6, 0),
        (try_end),
    ],
    "{!}CHEAT: Besiege the {reg6?town:castle}...",
    [
        (assign, "$g_player_besiege_town", "$g_encountered_party"),
        (jump_to_menu, "mnu_castle_besiege"),
    ], "."),

    ("center_reports", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT! Show reports.",
    [
        (jump_to_menu, "mnu_center_reports"),
    ], "."),

    ("sail_from_port", 
    [
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (eq, "$cheat_mode", 1),
    ],
    "{!}CHEAT: Sail from port.",
    [
        (assign, "$g_player_icon_state", 2),
        (party_set_flags, "p_main_party", 512, 1),
        (party_get_position, pos1, "p_main_party"),
        (map_get_water_position_around_position, 2, pos1, pos6),
        (party_set_position, "p_main_party", pos2),
        (assign, "$g_main_ship_party", -1),
        (change_screen_return),
    ], "."),

]),

("cannot_enter_court", 0,
"There is a feast in progress in the lord's hall, but you are not of sufficient status to be invited inside. Perhaps increasing your renown would win you admittance -- or you might also try distinguishing yourself at a tournament while the feast is in progress...",
"none", [],
[
    ("continue", [],
    "Continue",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("lady_visit", 0,
"Whom do you wish to visit?",
"none", [],
[
    ("visit_lady_1", 
    [
        (gt, "$love_interest_in_town", 0),
        (str_store_troop_name, s12, "$love_interest_in_town"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town"),
        (jump_to_menu, "mnu_garden"),
    ], "."),

    ("visit_lady_2", 
    [
        (gt, "$love_interest_in_town_2", 0),
        (str_store_troop_name, s12, "$love_interest_in_town_2"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town_2"),
        (jump_to_menu, "mnu_garden"),
    ], "."),

    ("visit_lady_3", 
    [
        (gt, "$love_interest_in_town_3", 0),
        (str_store_troop_name, s12, "$love_interest_in_town_3"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town_3"),
        (jump_to_menu, "mnu_garden"),
    ], "Door to the garden."),

    ("visit_lady_4", 
    [
        (gt, "$love_interest_in_town_4", 0),
        (str_store_troop_name, s12, "$love_interest_in_town_4"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town_4"),
        (jump_to_menu, "mnu_garden"),
    ], "."),

    ("visit_lady_5", 
    [
        (gt, "$love_interest_in_town_5", 0),
        (str_store_troop_name, s12, "$love_interest_in_town_5"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town_5"),
        (jump_to_menu, "mnu_garden"),
    ], "."),

    ("visit_lady_6", 
    [
        (gt, "$love_interest_in_town_6", 0),
        (str_store_troop_name, s12, "$love_interest_in_town_6"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town_6"),
        (jump_to_menu, "mnu_garden"),
    ], "."),

    ("visit_lady_7", 
    [
        (gt, "$love_interest_in_town_7", 0),
        (str_store_troop_name, s12, "$love_interest_in_town_7"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town_7"),
        (jump_to_menu, "mnu_garden"),
    ], "."),

    ("visit_lady_8", 
    [
        (gt, "$love_interest_in_town_8", 0),
        (str_store_troop_name, s12, "$love_interest_in_town_8"),
    ],
    "Visit {s12}",
    [
        (assign, "$love_interest_in_town", "$love_interest_in_town_8"),
        (jump_to_menu, "mnu_garden"),
    ], "."),

    ("leave", [],
    "Leave",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("town_tournament_lost", 0,
"You have been eliminated from the tournament.{s8}",
"none", 
[
    (str_clear, s8),
    (try_begin),
        (this_or_next|neg|eq, "$players_kingdom", "$g_encountered_party_faction"),
        (neg|troop_slot_ge, "trp_player", slot_troop_renown, 50),
        (neg|troop_slot_ge, "trp_player", slot_troop_renown, 125),
        (gt, "$g_player_tournament_placement", 4),
        (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_state, 6),
        (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_object, "$g_encountered_party"),
        (str_store_string, s8, "str__however_you_have_sufficiently_distinguished_yourself_to_be_invited_to_attend_the_ongoing_feast_in_the_lords_castle"),
    (try_end),
    (try_begin),
        (check_quest_active, "qst_order_tournament"),
        (quest_slot_eq, "qst_order_tournament", 1, "$current_town"),
        (quest_get_slot, ":var_0", "qst_order_tournament", 6),
        (store_troop_faction, ":var_1", ":var_0"),
        (str_store_faction_name, s9, ":var_1"),
        (str_store_string, s8, "@{s8}^Your bid to champion the {s9} ends in failure."),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town_tournament_won_by_another"),
    ], "."),

]),

("town_tournament_won", 512,
"You have won the tournament of {s3}! You are filled with pride as the crowd cheers your name. In addition to honor, fame and glory, you earn a prize of {reg9} denars. {s8}",
"none", 
[
    (str_store_party_name, s3, "$current_town"),
    (call_script, "script_change_troop_renown", "trp_player", 20),
    (call_script, "script_change_player_honor", 1),
    (call_script, "script_change_player_relation_with_center", "$current_town", 3),
    (val_add, "$g_tournaments_won", 1),
    (try_begin),
        (party_slot_eq, "$current_town", slot_town_lord, "trp_player"),
    (else_try),
        (party_get_slot, ":var_0", "$current_town", slot_town_prosperity),
        (val_add, ":var_0", 10),
        (party_set_slot, "$current_town", slot_town_prosperity, ":var_0"),
    (try_end),
    (str_clear, s8),
    (assign, reg9, 2000),
    (add_xp_to_troop, 250, "trp_player"),
    (try_begin),
        (check_quest_active, "qst_order_tournament"),
        (quest_slot_eq, "qst_order_tournament", 1, "$current_town"),
        (quest_get_slot, ":var_1", "qst_order_tournament", 6),
        (store_troop_faction, ":var_2", ":var_1"),
        (str_store_faction_name, s9, ":var_2"),
        (str_store_string, s8, "@However, you forfeit all material rewards and dedicate your victory to the glory of the {s9}!"),
    (else_try),
        (troop_add_gold, "trp_player", reg9),
    (try_end),
    (store_random_in_range, ":var_3", 0, 100),
    (try_begin),
        (eq, "$current_town", "p_castle_noldor"),
        (store_random_in_range, ":var_4", 0, 100),
        (store_random_in_range, ":var_5", 0, 100),
        (assign, ":var_6", 0),
        (try_begin),
            (neg|ge, ":var_3", 10),
            (assign, ":var_7", "itm_pop_qualis"),
        (else_try),
            (neg|ge, ":var_3", 40),
            (try_begin),
                (neg|ge, ":var_4", 50),
                (assign, ":var_7", "itm_pop_noldor_longsword"),
            (else_try),
                (neg|ge, ":var_4", 80),
                (assign, ":var_7", "itm_pop_noldor_runesword"),
            (else_try),
                (assign, ":var_7", "itm_pop_noldor_bastard"),
            (try_end),
            (try_begin),
                (neg|ge, ":var_5", 50),
                (assign, ":var_6", 10),
            (else_try),
                (neg|ge, ":var_5", 70),
                (assign, ":var_6", 13),
            (else_try),
                (neg|ge, ":var_5", 90),
                (assign, ":var_6", 14),
            (else_try),
                (assign, ":var_6", 17),
            (try_end),
        (else_try),
            (neg|ge, ":var_3", 50),
            (assign, ":var_7", "itm_pop_noldor_bow"),
            (try_begin),
                (neg|ge, ":var_5", 10),
                (assign, ":var_6", 17),
            (try_end),
        (else_try),
            (neg|ge, ":var_3", 80),
            (try_begin),
                (neg|ge, ":var_4", 10),
                (assign, ":var_7", "itm_pop_noldor_inf_helm"),
            (else_try),
                (neg|ge, ":var_4", 20),
                (assign, ":var_7", "itm_pop_noldor_capt_helm"),
            (else_try),
                (neg|ge, ":var_4", 25),
                (assign, ":var_7", "itm_pop_noldor_knight_helm"),
            (else_try),
                (neg|ge, ":var_4", 30),
                (assign, ":var_7", "itm_pop_noldor_noble_armor"),
            (else_try),
                (neg|ge, ":var_4", 35),
                (assign, ":var_7", "itm_pop_noldor_ranger_garb"),
            (else_try),
                (neg|ge, ":var_4", 50),
                (assign, ":var_7", "itm_pop_noldor_archer_garb"),
            (else_try),
                (neg|ge, ":var_4", 65),
                (assign, ":var_7", "itm_pop_noldor_female_armor"),
            (else_try),
                (neg|ge, ":var_4", 75),
                (assign, ":var_7", "itm_pop_noldor_rune_armor"),
            (else_try),
                (neg|ge, ":var_4", 80),
                (assign, ":var_7", "itm_pop_noldor_ancient_plate"),
            (else_try),
                (assign, ":var_7", "itm_pop_noldor_boots"),
            (try_end),
            (try_begin),
                (neg|ge, ":var_5", 60),
                (assign, ":var_6", 25),
            (else_try),
                (neg|ge, ":var_5", 90),
                (assign, ":var_6", 27),
            (else_try),
                (assign, ":var_6", 29),
            (try_end),
            (try_begin),
                (eq, ":var_7", "itm_pop_noldor_boots"),
                (try_begin),
                    (eq, ":var_6", 27),
                    (assign, ":var_6", 24),
                (else_try),
                    (eq, ":var_6", 29),
                    (assign, ":var_6", 26),
                (try_end),
            (try_end),
        (else_try),
            (try_begin),
                (neg|ge, ":var_4", 20),
                (assign, ":var_7", "itm_pop_noldor_grey_horse"),
            (else_try),
                (neg|ge, ":var_4", 40),
                (assign, ":var_7", "itm_pop_noldor_dark_horse"),
            (else_try),
                (neg|ge, ":var_4", 60),
                (assign, ":var_7", "itm_pop_noldor_gold_horse"),
            (else_try),
                (neg|ge, ":var_4", 90),
                (assign, ":var_7", "itm_pop_noldor_pony_horse"),
            (else_try),
                (assign, ":var_7", "itm_pop_noldor_spirit_horse"),
            (try_end),
            (try_begin),
                (neg|ge, ":var_5", 30),
                (assign, ":var_6", 35),
            (else_try),
                (neg|ge, ":var_5", 60),
                (assign, ":var_6", 18),
            (else_try),
                (neg|ge, ":var_5", 90),
                (assign, ":var_6", 32),
            (else_try),
                (assign, ":var_6", 36),
            (try_end),
        (try_end),
        (troop_add_item, "trp_player", ":var_7", ":var_6"),
        (str_store_item_name, s21, ":var_7"),
        (str_store_string, s8, "@Additionally, you have been presented with an exquisite {s21} from the Noldor Council."),
    (else_try),
        (this_or_next|neg|check_quest_active, "qst_order_tournament"),
        (neg|quest_slot_eq, "qst_order_tournament", 1, "$current_town"),
        (neg|ge, ":var_3", 10),
        (store_random_in_range, ":var_7", "itm_pl_460", "itm_pop_sallet_open"),
        (troop_add_item, "trp_player", ":var_7"),
        (str_store_item_name, s21, ":var_7"),
        (str_store_string, s8, "@Additionally, you have been presented with a {s21} from the town Steward."),
    (try_end),
    (store_add, ":var_8", "$g_tournament_bet_placed", "$g_tournament_bet_win_amount"),
    (try_begin),
        (gt, "$g_tournament_bet_win_amount", 0),
        (assign, reg8, ":var_8"),
        (str_store_string, s8, "@ {s8}^Moreover, you earn {reg8} denars from the clever bets you placed on yourself..."),
    (try_end),
    (try_begin),
        (this_or_next|neg|eq, "$players_kingdom", "$g_encountered_party_faction"),
        (neg|troop_slot_ge, "trp_player", slot_troop_renown, 70),
        (neg|troop_slot_ge, "trp_player", slot_troop_renown, 145),
        (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_state, 6),
        (faction_slot_eq, "$g_encountered_party_faction", slot_faction_ai_object, "$g_encountered_party"),
        (str_store_string, s8, "str_s8_you_are_also_invited_to_attend_the_ongoing_feast_in_the_castle"),
    (try_end),
    (troop_add_gold, "trp_player", ":var_8"),
    (assign, ":var_9", 0),
    (store_div, ":var_9", "$g_tournament_bet_win_amount", 5),
    (party_get_slot, ":var_10", "$current_town", slot_town_player_odds),
    (val_sub, ":var_10", ":var_9"),
    (val_max, ":var_10", 250),
    (party_set_slot, "$current_town", slot_town_player_odds, ":var_10"),
    (call_script, "script_play_victorious_sound"),
    (unlock_achievement, 33),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
            (eq, "$current_town", "p_castle_noldor"),
            (jump_to_menu, "mnu_noldor_castle"),
        (else_try),
            (jump_to_menu, "mnu_town"),
        (try_end),
    ], "."),

]),

("town_tournament_won_by_another", 512,
"As the only {reg3?fighter:man} to remain undefeated this day, {s1} wins the lists and the glory of this tournament.",
"none", 
[
    (call_script, "script_get_num_tournament_participants"),
    (store_sub, ":var_0", reg0, 1),
    (try_begin),
        (troop_slot_eq, "trp_tournament_participants", slot_troop_relations_begin, 0),
        (troop_set_slot, "trp_tournament_participants", slot_troop_relations_begin, -1),
        (val_sub, ":var_0", 1),
    (try_end),
    (call_script, "script_remove_tournament_participants_randomly", ":var_0"),
    (call_script, "script_sort_tournament_participant_troops"),
    (troop_get_slot, ":var_1", "trp_tournament_participants", slot_troop_relations_begin),
    (str_store_troop_name, s1, ":var_1"),
    (try_begin),
        (troop_is_hero, ":var_1"),
        (call_script, "script_change_troop_renown", ":var_1", 20),
    (try_end),
    (troop_get_type, reg3, ":var_1"),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
            (eq, "$current_town", "p_castle_noldor"),
            (jump_to_menu, "mnu_noldor_castle"),
        (else_try),
            (jump_to_menu, "mnu_town"),
        (try_end),
    ], "."),

]),

("town_tournament", 512,
"{s1}You are at tier {reg0} of the tournament, with {reg1} participants remaining. In the next round, there will be {reg2} teams with {reg3} {reg4?fighters:fighter} each.",
"none", 
[
    (party_set_slot, "$current_town", slot_town_has_tournament, 0),
    (call_script, "script_sort_tournament_participant_troops"),
    (call_script, "script_get_num_tournament_participants"),
    (assign, ":var_0", reg0),
    (try_begin),
        (neg|troop_slot_eq, "trp_tournament_participants", slot_troop_relations_begin, 0),
        (assign, ":var_1", 0),
        (store_div, ":var_1", "$g_tournament_bet_placed", 5),
        (party_get_slot, ":var_2", "$current_town", slot_town_player_odds),
        (val_add, ":var_2", ":var_1"),
        (val_min, ":var_2", 4000),
        (party_set_slot, "$current_town", slot_town_player_odds, ":var_2"),
        (try_begin),
            (check_quest_active, "qst_order_tournament"),
            (quest_slot_eq, "qst_order_tournament", 1, "$current_town"),
            (call_script, "script_fail_quest", "qst_order_tournament"),
        (try_end),
        (jump_to_menu, "mnu_town_tournament_lost"),
    (else_try),
        (eq, ":var_0", 1),
        (try_begin),
            (check_quest_active, "qst_order_tournament"),
            (quest_slot_eq, "qst_order_tournament", 1, "$current_town"),
            (call_script, "script_succeed_quest", "qst_order_tournament"),
        (try_end),
        (jump_to_menu, "mnu_town_tournament_won"),
    (else_try),
        (try_begin),
            (neg|gt, "$g_tournament_next_num_teams", 0),
            (call_script, "script_get_random_tournament_team_amount_and_size"),
            (assign, "$g_tournament_next_num_teams", reg0),
            (assign, "$g_tournament_next_team_size", reg1),
        (try_end),
        (assign, reg2, "$g_tournament_next_num_teams"),
        (assign, reg3, "$g_tournament_next_team_size"),
        (store_sub, reg4, reg3, 1),
        (str_clear, s1),
        (try_begin),
            (eq, "$g_tournament_player_team_won", 1),
            (str_store_string, s1, "@Victory is yours! You have won this melee, but now you must prepare yourself for the next round. "),
        (else_try),
            (eq, "$g_tournament_player_team_won", 0),
            (str_store_string, s1, "@You have been bested in this melee, but the master of ceremonies declares a recognition of your skill and bravery, allowing you to take part in the next round. "),
        (try_end),
        (assign, reg1, ":var_0"),
        (store_add, reg0, "$g_tournament_cur_tier", 1),
    (try_end),
],
[
    ("tournament_view_participants", [],
    "View participants.",
    [
        (jump_to_menu, "mnu_tournament_participants"),
    ], "."),

    ("tournament_bet", 
    [
        (neg|eq, "$g_tournament_cur_tier", "$g_tournament_last_bet_tier"),
        (this_or_next|neg|check_quest_active, "qst_order_tournament"),
        (neg|quest_slot_eq, "qst_order_tournament", 1, "$current_town"),
    ],
    "Place a bet on yourself.",
    [
        (jump_to_menu, "mnu_tournament_bet"),
    ], "."),

    ("tournament_join_next_fight", [],
    "Fight in the next round.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_arena),
        (modify_visitors_at_site, ":var_0"),
        (reset_visitors),
        (assign, "$g_player_tournament_placement", "$g_tournament_cur_tier"),
        (try_begin),
            (gt, "$g_player_tournament_placement", 4),
            (assign, "$g_player_eligible_feast_center_no", "$current_town"),
        (try_end),
        (val_add, "$g_tournament_cur_tier", 1),
        (store_mul, "$g_tournament_num_participants_for_fight", "$g_tournament_next_num_teams", "$g_tournament_next_team_size"),
        (troop_set_slot, "trp_tournament_participants", slot_troop_relations_begin, -1),
        (troop_set_slot, "trp_temp_array_a", slot_troop_relations_begin, "trp_player"),
        (try_for_range, ":var_1", 1, "$g_tournament_num_participants_for_fight"),
            (call_script, "script_get_random_tournament_participant"),
            (troop_set_slot, "trp_temp_array_a", ":var_1", reg0),
        (try_end),
        (call_script, "script_shuffle_troop_slots", "trp_temp_array_a", 0, "$g_tournament_num_participants_for_fight"),
        (try_for_range, ":var_1", 0, 4),
            (troop_set_slot, "trp_temp_array_b", ":var_1", ":var_1"),
        (try_end),
        (call_script, "script_shuffle_troop_slots", "trp_temp_array_b", 0, 4),
        (assign, ":var_2", 0),
        (try_for_range, ":var_3", 0, "$g_tournament_next_num_teams"),
            (troop_get_slot, ":var_4", "trp_temp_array_b", ":var_3"),
            (try_for_range, ":var_1", 0, 8),
                (troop_set_slot, "trp_temp_array_c", ":var_1", ":var_1"),
            (try_end),
            (call_script, "script_shuffle_troop_slots", "trp_temp_array_c", 0, 8),
            (try_for_range, ":var_5", 0, "$g_tournament_next_team_size"),
                (store_mul, ":var_6", ":var_4", 8),
                (troop_get_slot, ":var_7", "trp_temp_array_c", ":var_5"),
                (val_add, ":var_6", ":var_7"),
                (troop_get_slot, ":var_8", "trp_temp_array_a", ":var_2"),
                (set_visitor, ":var_6", ":var_8"),
                (val_add, ":var_2", 1),
            (try_end),
        (try_end),
        (assign, "$g_tournament_next_num_teams", 0),
        (assign, "$g_tournament_next_team_size", 0),
        (assign, "$g_mt_mode", 3),
        (party_get_slot, ":var_9", "$current_town", slot_center_original_faction),
        (assign, ":var_10", 0),
        (assign, ":var_11", "p_castle_1"),
        (try_for_range, ":var_12", "p_town_1", ":var_11"),
            (try_begin),
                (eq, ":var_12", "$current_town"),
                (assign, ":var_11", 0),
            (else_try),
                (party_slot_eq, ":var_12", slot_center_original_faction, ":var_9"),
                (val_add, ":var_10", 1),
            (try_end),
        (try_end),
        (set_jump_mission, "mt_arena_melee_fight"),
        (try_begin),
            (eq, ":var_9", "fac_kingdom_1"),
            (store_mod, ":var_13", ":var_10", 4),
            (try_begin),
                (eq, ":var_13", 0),
                (call_script, "script_set_items_for_tournament", 40, 80, 50, 20, 0, 0, 0, 0, "itm_arena_armor_red", "itm_tourney_helm_red"),
            (else_try),
                (eq, ":var_13", 1),
                (call_script, "script_set_items_for_tournament", 100, 100, 0, 0, 0, 0, 0, 0, "itm_arena_armor_red", "itm_tourney_helm_red"),
            (else_try),
                (eq, ":var_13", 2),
                (call_script, "script_set_items_for_tournament", 100, 0, 100, 0, 0, 0, 0, 0, "itm_arena_armor_red", "itm_tourney_helm_red"),
            (else_try),
                (eq, ":var_13", 3),
                (call_script, "script_set_items_for_tournament", 40, 80, 50, 20, 40, 0, 0, 0, "itm_arena_armor_red", "itm_tourney_helm_red"),
            (try_end),
        (else_try),
            (eq, ":var_9", "fac_kingdom_2"),
            (store_mod, ":var_13", ":var_10", 4),
            (try_begin),
                (eq, ":var_13", 0),
                (call_script, "script_set_items_for_tournament", 40, 80, 50, 20, 0, 0, 0, 0, "itm_arena_armor_red", "itm_steppe_helmet_red"),
            (else_try),
                (eq, ":var_13", 1),
                (call_script, "script_set_items_for_tournament", 100, 50, 0, 0, 0, 20, 30, 0, "itm_arena_armor_red", "itm_steppe_helmet_red"),
            (else_try),
                (eq, ":var_13", 2),
                (call_script, "script_set_items_for_tournament", 100, 0, 50, 0, 0, 20, 30, 0, "itm_arena_armor_red", "itm_steppe_helmet_red"),
            (else_try),
                (eq, ":var_13", 3),
                (call_script, "script_set_items_for_tournament", 40, 80, 50, 20, 30, 0, 60, 0, "itm_arena_armor_red", "itm_steppe_helmet_red"),
            (try_end),
        (else_try),
            (eq, ":var_9", "fac_kingdom_3"),
            (store_mod, ":var_13", ":var_10", 2),
            (try_begin),
                (eq, ":var_13", 0),
                (call_script, "script_set_items_for_tournament", 100, 0, 0, 0, 0, 40, 60, 0, "itm_arena_tunic_red", "itm_steppe_helmet_red"),
            (else_try),
                (eq, ":var_13", 1),
                (call_script, "script_set_items_for_tournament", 100, 50, 25, 0, 0, 30, 50, 0, "itm_arena_tunic_red", "itm_steppe_helmet_red"),
            (try_end),
        (else_try),
            (eq, ":var_9", "fac_kingdom_4"),
            (store_mod, ":var_13", ":var_10", 3),
            (try_begin),
                (eq, ":var_13", 0),
                (call_script, "script_set_items_for_tournament", 0, 0, 50, 80, 0, 0, 0, 0, "itm_arena_armor_red", -1),
            (else_try),
                (eq, ":var_13", 1),
                (call_script, "script_set_items_for_tournament", 0, 0, 50, 80, 50, 0, 0, 0, "itm_arena_armor_red", -1),
            (else_try),
                (eq, ":var_13", 2),
                (call_script, "script_set_items_for_tournament", 40, 0, 0, 100, 0, 0, 0, 0, "itm_arena_armor_red", -1),
            (try_end),
        (else_try),
            (eq, ":var_9", "fac_kingdom_5"),
            (call_script, "script_set_items_for_tournament", 25, 100, 60, 0, 30, 0, 30, 50, "itm_arena_tunic_red", "itm_arena_helmet_red"),
        (else_try),
            (eq, ":var_9", "fac_noldor_castle"),
            (call_script, "script_set_items_for_tournament", 25, 0, 50, 0, 70, 0, 30, 0, "itm_arena_tunic_red", "itm_arena_helmet_red"),
        (try_end),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("leave_tournament", [],
    "Withdraw from the tournament.",
    [
        (jump_to_menu, "mnu_tournament_withdraw_verify"),
    ], "."),

]),

("tournament_withdraw_verify", 0,
"Are you sure you want to withdraw from the tournament?",
"none", [],
[
    ("tournament_withdraw_yes", [],
    "Yes. This is a pointless affectation.",
    [
        (jump_to_menu, "mnu_town_tournament_won_by_another"),
    ], "."),

    ("tournament_withdraw_no", [],
    "No, not as long as there is a chance of victory!",
    [
        (jump_to_menu, "mnu_town_tournament"),
    ], "."),

]),

("tournament_bet", 0,
"The odds against you are {reg5} to {reg6}.{reg1? You have already bet {reg1} denars on yourself, and if you win, you will earn {reg2} denars.:} How much do you want to bet?",
"none", 
[
    (assign, reg1, "$g_tournament_bet_placed"),
    (store_add, reg2, "$g_tournament_bet_win_amount", "$g_tournament_bet_placed"),
    (call_script, "script_get_win_amount_for_tournament_bet"),
    (assign, ":var_0", reg0),
    (assign, ":var_1", 100000),
    (assign, ":var_2", 1),
    (assign, ":var_3", 1),
    (try_for_range, ":var_4", 1, 50),
        (try_for_range, ":var_5", 1, 50),
            (store_mul, ":var_6", 100, ":var_4"),
            (val_div, ":var_6", ":var_5"),
            (store_sub, ":var_7", ":var_0", ":var_6"),
            (val_abs, ":var_7"),
            (neg|ge, ":var_7", ":var_1"),
            (assign, ":var_1", ":var_7"),
            (assign, ":var_2", ":var_5"),
            (assign, ":var_3", ":var_4"),
        (try_end),
    (try_end),
    (assign, reg5, ":var_3"),
    (assign, reg6, ":var_2"),
],
[
    ("bet_500_denars", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", 500),
    ],
    "500 denars.",
    [
        (assign, "$temp", 500),
        (jump_to_menu, "mnu_tournament_bet_confirm"),
    ], "."),

    ("bet_250_denars", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", 250),
    ],
    "250 denars.",
    [
        (assign, "$temp", 250),
        (jump_to_menu, "mnu_tournament_bet_confirm"),
    ], "."),

    ("bet_100_denars", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", 100),
    ],
    "100 denars.",
    [
        (assign, "$temp", 100),
        (jump_to_menu, "mnu_tournament_bet_confirm"),
    ], "."),

    ("bet_50_denars", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", 50),
    ],
    "50 denars.",
    [
        (assign, "$temp", 50),
        (jump_to_menu, "mnu_tournament_bet_confirm"),
    ], "."),

    ("bet_25_denars", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", 25),
    ],
    "25 denars.",
    [
        (assign, "$temp", 25),
        (jump_to_menu, "mnu_tournament_bet_confirm"),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_town_tournament"),
    ], "."),

]),

("tournament_bet_confirm", 0,
"If you bet {reg1} denars, you will earn {reg2} denars if you win the tournament. Is that all right?",
"none", 
[
    (call_script, "script_get_win_amount_for_tournament_bet"),
    (assign, ":var_0", reg0),
    (val_mul, ":var_0", "$temp"),
    (val_div, ":var_0", 100),
    (assign, reg1, "$temp"),
    (assign, reg2, ":var_0"),
],
[
    ("tournament_bet_accept", [],
    "Go ahead.",
    [
        (call_script, "script_tournament_place_bet", "$temp"),
        (jump_to_menu, "mnu_town_tournament"),
    ], "."),

    ("tournament_bet_cancel", [],
    "Forget it.",
    [
        (jump_to_menu, "mnu_tournament_bet"),
    ], "."),

]),

("tournament_participants", 0,
"You ask one of the criers for the names of the tournament participants. They are:^{s11}",
"none", 
[
    (str_clear, s11),
    (call_script, "script_sort_tournament_participant_troops"),
    (call_script, "script_get_num_tournament_participants"),
    (assign, ":var_0", reg0),
    (try_for_range, ":var_1", 0, ":var_0"),
        (troop_get_slot, ":var_2", "trp_tournament_participants", ":var_1"),
        (str_store_troop_name, s12, ":var_2"),
        (str_store_string, s11, "@{!}{s11}^{s12}"),
    (try_end),
],
[
    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_town_tournament"),
    ], "."),

]),

("collect_taxes", 512,
"As the party member with the highest trade skill ({reg2}), {reg3?you expect:{s1} expects} that collecting taxes from here will take {reg4} days...",
"none", 
[
    (call_script, "script_get_max_skill_of_player_party", "skl_trade"),
    (assign, ":var_0", reg0),
    (assign, reg2, reg0),
    (assign, ":var_1", reg1),
    (try_begin),
        (eq, ":var_1", "trp_player"),
        (assign, reg3, 1),
    (else_try),
        (assign, reg3, 0),
        (str_store_troop_name, s1, ":var_1"),
    (try_end),
    (assign, ":var_2", 3000),
    (try_begin),
        (party_slot_eq, "$current_town", slot_party_type, 3),
        (assign, ":var_2", 6000),
    (try_end),
    (try_begin),
        (quest_slot_eq, "qst_collect_taxes", 11, 0),
        (store_add, ":var_3", ":var_0", 30),
        (try_begin),
            (party_slot_eq, "$current_town", slot_party_type, 3),
            (store_div, "$qst_collect_taxes_total_hours", 5040, ":var_3"),
        (else_try),
            (store_div, "$qst_collect_taxes_total_hours", 2160, ":var_3"),
        (try_end),
        (call_script, "script_party_count_fit_for_battle", "p_main_party"),
        (val_add, reg0, 20),
        (val_mul, "$qst_collect_taxes_total_hours", 20),
        (val_div, "$qst_collect_taxes_total_hours", reg0),
        (quest_set_slot, "qst_collect_taxes", 10, "$qst_collect_taxes_total_hours"),
        (store_div, ":var_4", "$qst_collect_taxes_total_hours", 20),
        (store_div, ":var_5", "$qst_collect_taxes_total_hours", 4),
        (assign, ":var_6", ":var_5"),
        (store_mul, ":var_7", "$qst_collect_taxes_total_hours", 3),
        (val_div, ":var_7", 4),
        (val_mul, ":var_2", 2),
        (store_div, "$qst_collect_taxes_hourly_income", ":var_2", "$qst_collect_taxes_total_hours"),
        (store_random_in_range, "$qst_collect_taxes_menu_counter", ":var_4", ":var_5"),
        (store_random_in_range, "$qst_collect_taxes_unrest_counter", ":var_6", ":var_7"),
        (assign, "$qst_collect_taxes_halve_taxes", 0),
    (try_end),
    (quest_get_slot, ":var_8", "qst_collect_taxes", 10),
    (store_div, ":var_9", ":var_8", 24),
    (val_mul, ":var_9", 24),
    (try_begin),
        (neg|ge, ":var_9", ":var_8"),
        (val_add, ":var_9", 24),
    (try_end),
    (val_div, ":var_9", 24),
    (assign, reg4, ":var_9"),
],
[
    ("start_collecting", [],
    "Start collecting.",
    [
        (assign, "$qst_collect_taxes_currently_collecting", 1),
        (try_begin),
            (quest_slot_eq, "qst_collect_taxes", 11, 0),
            (quest_set_slot, "qst_collect_taxes", 11, 1),
        (try_end),
        (rest_for_hours_interactive, 1000, 5, 0),
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_town_visit_after_rest", 1),
        (change_screen_return),
    ], "."),

    ("collect_later", [],
    "Put it off until later.",
    [
        (try_begin),
            (party_slot_eq, "$current_town", slot_party_type, 3),
            (jump_to_menu, "mnu_town"),
        (else_try),
            (jump_to_menu, "mnu_village"),
        (try_end),
    ], "."),

]),

("collect_taxes_complete", 512,
"You've collected {reg3} denars in taxes from {s3}. {s19} will be expecting you to take the money to him.",
"none", 
[
    (str_store_party_name, s3, "$current_town"),
    (quest_get_slot, ":var_0", "qst_collect_taxes", 6),
    (str_store_troop_name, s19, ":var_0"),
    (quest_get_slot, reg3, "qst_collect_taxes", 22),
    (try_begin),
        (eq, "$qst_collect_taxes_halve_taxes", 0),
        (call_script, "script_change_player_relation_with_center", "$current_town", -2),
    (try_end),
    (call_script, "script_succeed_quest", "qst_collect_taxes"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("collect_taxes_rebels_killed", 0,
"Your quick action and strong arm have successfully put down the revolt. Surely, anyone with a mind to rebel against you will think better of it after this.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("collect_taxes_failed", 512,
"You could collect only {reg3} denars as tax from {s3} before the revolt broke out. {s1} won't be happy, but some silver will placate him better than nothing at all...",
"none", 
[
    (str_store_party_name, s3, "$current_town"),
    (quest_get_slot, ":var_0", "qst_collect_taxes", 6),
    (str_store_troop_name, s1, ":var_0"),
    (quest_get_slot, reg3, "qst_collect_taxes", 22),
    (call_script, "script_fail_quest", "qst_collect_taxes"),
    (quest_set_slot, "qst_collect_taxes", 11, 4),
    (rest_for_hours, 0, 0, 0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_map),
    ], "."),

]),

("collect_taxes_revolt_warning", 0,
"The people of {s3} are outraged at your demands and decry it as nothing more than extortion. They're getting very restless, and they may react badly if you keep pressing them.",
"none", 
[
    (str_store_party_name, s3, "$current_town"),
],
[
    ("continue_collecting_taxes", [],
    "Ignore them and continue.",
    [
        (change_screen_return),
    ], "."),

    ("halve_taxes", 
    [
        (quest_get_slot, ":var_0", "qst_collect_taxes", 6),
        (str_store_troop_name, s1, ":var_0"),
    ],
    "Agree to reduce your collection by half. ({s1} may be upset)",
    [
        (assign, "$qst_collect_taxes_halve_taxes", 1),
        (change_screen_return),
    ], "."),

]),

("collect_taxes_revolt", 0,
"You are interrupted while collecting the taxes at {s3}. A large band of angry {reg9?peasants:townsmen} is marching nearer, shouting about the exorbitant taxes and waving torches and weapons. It looks like they aim to fight you!",
"none", 
[
    (str_store_party_name, s3, "$current_town"),
    (assign, reg9, 0),
    (try_begin),
        (party_slot_eq, "$current_town", slot_party_type, 4),
        (assign, reg9, 1),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (set_jump_mission, "mt_back_alley_revolt"),
        (quest_get_slot, ":var_0", "qst_collect_taxes", 1),
        (try_begin),
            (party_slot_eq, ":var_0", slot_party_type, 3),
            (party_get_slot, ":var_1", ":var_0", slot_town_alley),
        (else_try),
            (party_get_slot, ":var_1", ":var_0", slot_town_center),
        (try_end),
        (modify_visitors_at_site, ":var_1"),
        (reset_visitors),
        (assign, ":var_2", 6),
        (store_character_level, ":var_3", "trp_player"),
        (val_div, ":var_3", 5),
        (val_add, ":var_2", ":var_3"),
        (set_visitors, 1, "trp_tax_rebel", ":var_2"),
        (jump_to_scene, ":var_1"),
        (change_screen_mission),
    ], "."),

]),

("train_peasants_against_bandits", 0,
"As the party member with the highest training skill ({reg2}), {reg3?you expect:{s1} expects} that getting some peasants ready for practice will take {reg4} hours.",
"none", 
[
    (call_script, "script_get_max_skill_of_player_party", "skl_trainer"),
    (assign, ":var_0", reg0),
    (assign, reg2, reg0),
    (assign, ":var_1", reg1),
    (try_begin),
        (eq, ":var_1", "trp_player"),
        (assign, reg3, 1),
    (else_try),
        (assign, reg3, 0),
        (str_store_troop_name, s1, ":var_1"),
    (try_end),
    (store_sub, ":var_2", 20, ":var_0"),
    (val_mul, ":var_2", 3),
    (val_div, ":var_2", 5),
    (store_sub, reg4, ":var_2", "$qst_train_peasants_against_bandits_num_hours_trained"),
],
[
    ("make_preparation", [],
    "Train them.",
    [
        (assign, "$qst_train_peasants_against_bandits_currently_training", 1),
        (rest_for_hours_interactive, 1000, 5, 0),
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_town_visit_after_rest", 1),
        (change_screen_return),
    ], "."),

    ("train_later", [],
    "Put it off until later.",
    [
        (jump_to_menu, "mnu_village"),
    ], "."),

]),

("train_peasants_against_bandits_ready", 0,
"You put the peasants through the basics of soldiering, discipline and obedience. You think {reg0} of them {reg1?have:has} fully grasped the training and {reg1?are:is} ready for some practice.",
"none", 
[
    (store_character_level, ":var_0", "trp_player"),
    (val_div, ":var_0", 10),
    (val_add, ":var_0", 1),
    (quest_get_slot, ":var_1", "qst_train_peasants_against_bandits", 10),
    (quest_get_slot, ":var_2", "qst_train_peasants_against_bandits", 11),
    (val_sub, ":var_1", ":var_2"),
    (assign, ":var_3", ":var_0"),
    (val_min, ":var_3", ":var_1"),
    (val_add, ":var_3", 1),
    (store_random_in_range, ":var_4", 1, ":var_3"),
    (assign, "$g_train_peasants_against_bandits_num_peasants", ":var_4"),
    (assign, reg0, ":var_4"),
    (store_sub, reg1, ":var_4", 1),
    (str_store_troop_name_by_count, s0, "trp_trainee_peasant", ":var_4"),
],
[
    ("peasant_start_practice", [],
    "Start the practice fight.",
    [
        (set_jump_mission, "mt_village_training"),
        (quest_get_slot, ":var_0", "qst_train_peasants_against_bandits", 1),
        (party_get_slot, ":var_1", ":var_0", slot_town_center),
        (modify_visitors_at_site, ":var_1"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitors, 1, "trp_trainee_peasant", "$g_train_peasants_against_bandits_num_peasants"),
        (set_jump_entry, 11),
        (jump_to_scene, ":var_1"),
        (jump_to_menu, "mnu_train_peasants_against_bandits_training_result"),
        (music_set_situation, 0),
        (change_screen_mission),
    ], "."),

]),

("train_peasants_against_bandits_training_result", 512,
"{s0}",
"none", 
[
    (assign, reg5, "$g_train_peasants_against_bandits_num_peasants"),
    (str_store_troop_name_by_count, s0, "trp_trainee_peasant", "$g_train_peasants_against_bandits_num_peasants"),
    (try_begin),
        (eq, "$g_train_peasants_against_bandits_training_succeeded", 0),
        (str_store_string, s0, "@You were beaten. The peasants are heartened by their success, but the lesson you wanted to teach them probably didn't get through..."),
    (else_try),
        (str_store_string, s0, "@After beating your last opponent, you explain to the peasants how to better defend themselves against such an attack. Hopefully they'll take the experience on board and will be prepared next time."),
        (quest_get_slot, ":var_0", "qst_train_peasants_against_bandits", 11),
        (val_add, ":var_0", "$g_train_peasants_against_bandits_num_peasants"),
        (quest_set_slot, "qst_train_peasants_against_bandits", 11, ":var_0"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
            (quest_get_slot, ":var_0", "qst_train_peasants_against_bandits", 11),
            (quest_slot_eq, "qst_train_peasants_against_bandits", 10, ":var_0"),
            (jump_to_menu, "mnu_train_peasants_against_bandits_attack"),
        (else_try),
            (change_screen_map),
        (try_end),
    ], "."),

]),

("train_peasants_against_bandits_attack", 0,
"As you get ready to continue the training, a sentry from the village runs up to you, shouting alarums. The bandits have been spotted on the horizon, riding hard for {s3}. The elder begs that you organize your newly-trained militia and face them.",
"none", 
[
    (str_store_party_name, s3, "$current_town"),
],
[
    ("peasants_against_bandits_attack_resist", [],
    "Prepare for a fight!",
    [
        (store_random_in_range, ":var_0", 0, 3),
        (try_begin),
            (eq, ":var_0", 0),
            (assign, ":var_1", "trp_bandit"),
        (else_try),
            (eq, ":var_0", 1),
            (assign, ":var_1", "trp_mountain_bandit"),
        (else_try),
            (assign, ":var_1", "trp_forest_bandit"),
        (try_end),
        (party_get_slot, ":var_2", "$g_encountered_party", slot_town_center),
        (modify_visitors_at_site, ":var_2"),
        (reset_visitors),
        (store_character_level, ":var_3", "trp_player"),
        (val_div, ":var_3", 2),
        (store_add, ":var_4", ":var_3", 16),
        (store_add, ":var_5", ":var_4", 6),
        (store_random_in_range, ":var_0", ":var_4", ":var_5"),
        (set_visitors, 0, ":var_1", ":var_0"),
        (assign, ":var_6", ":var_5"),
        (set_visitors, 2, "trp_trainee_peasant", ":var_6"),
        (set_party_battle_mode),
        (set_battle_advantage, 0),
        (assign, "$g_battle_result", 0),
        (set_jump_mission, "mt_village_attack_bandits"),
        (jump_to_scene, ":var_2"),
        (assign, "$g_next_menu", "mnu_train_peasants_against_bandits_attack_result"),
        (jump_to_menu, "mnu_battle_debrief"),
        (assign, "$g_mt_mode", 2),
        (change_screen_mission),
    ], "."),

]),

("train_peasants_against_bandits_attack_result", 4608,
"{s9}",
"none", 
[
    (try_begin),
        (eq, "$g_battle_result", 1),
        (str_store_string, s9, "@The bandits are broken! Those few who remain alive and conscious run off with their tails between their legs, terrified of the peasants and their new champion."),
        (call_script, "script_succeed_quest", "qst_train_peasants_against_bandits"),
        (jump_to_menu, "mnu_train_peasants_against_bandits_success"),
    (else_try),
        (call_script, "script_fail_quest", "qst_train_peasants_against_bandits"),
        (str_store_string, s9, "@Try as you might, you could not defeat the bandits. Infuriated, they raze the village to the ground to punish the peasants, and then leave the burning wasteland behind to find greener pastures to plunder."),
        (set_background_mesh, "mesh_pic_looted_village"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
            (call_script, "script_village_set_state", "$current_town", 2),
            (party_set_slot, "$current_town", slot_village_raid_progress, 0),
            (party_set_slot, "$current_town", slot_village_recover_progress, 0),
            (call_script, "script_change_player_relation_with_center", "$g_encountered_party", -3),
            (call_script, "script_end_quest", "qst_train_peasants_against_bandits"),
        (try_end),
        (change_screen_map),
    ], "."),

]),

("train_peasants_against_bandits_success", 512,
"The bandits are broken! Those few who remain run off with their tails between their legs, terrified of the peasants and their new champion. The villagers have little left in the way of wealth after their ordeal, but they offer you all they can find to show their gratitude.",
"none", 
[
    (party_clear, "p_temp_party"),
    (call_script, "script_end_quest", "qst_train_peasants_against_bandits"),
    (call_script, "script_change_player_relation_with_center", "$g_encountered_party", 4),
    (party_get_slot, ":var_0", "$current_town", slot_town_elder),
    (try_for_range, ":var_1", 10, 106),
        (store_random_in_range, ":var_2", 0, 100),
        (neg|ge, ":var_2", 50),
        (troop_set_inventory_slot, ":var_0", ":var_1", -1),
    (try_end),
    (call_script, "script_add_log_entry", 4, "trp_player", "$current_town", -1, -1),
],
[
    ("village_bandits_defeated_accept", [],
    "Take it as your just due.",
    [
        (jump_to_menu, "mnu_auto_return_to_map"),
        (party_get_slot, ":var_0", "$current_town", slot_town_elder),
        (troop_sort_inventory, ":var_0"),
        (change_screen_loot, ":var_0"),
    ], "."),

    ("village_bandits_defeated_cont", [],
    "Refuse, stating that they need these items more than you do.",
    [
        (call_script, "script_change_player_relation_with_center", "$g_encountered_party", 3),
        (call_script, "script_change_player_honor", 3),
        (change_screen_map),
    ], "."),

]),

("disembark", 0,
"Do you wish to disembark?",
"none", [],
[
    ("disembark_yes", [],
    "Yes.",
    [
        (assign, "$g_player_icon_state", 0),
        (party_set_flags, "p_main_party", 512, 0),
        (party_get_position, pos1, "p_main_party"),
        (party_set_position, "p_main_party", pos0),
        (try_begin),
            (neg|gt, "$g_main_ship_party", 0),
            (set_spawn_radius, 0),
            (spawn_around_party, "p_main_party", "pt_none"),
            (assign, "$g_main_ship_party", reg0),
            (party_set_flags, "$g_main_ship_party", 2115072, 1),
            (str_store_troop_name, s1, "trp_player"),
            (party_set_name, "$g_main_ship_party", "@{s1}'s Ship"),
            (party_set_icon, "$g_main_ship_party", "icon_ship"),
            (party_set_slot, "$g_main_ship_party", slot_party_type, 16),
        (try_end),
        (enable_party, "$g_main_ship_party"),
        (party_set_position, "$g_main_ship_party", pos0),
        (party_set_icon, "$g_main_ship_party", "icon_ship_on_land"),
        (assign, "$g_main_ship_party", -1),
        (change_screen_return),
    ], "."),

    ("disembark_no", [],
    "No.",
    [
        (change_screen_return),
    ], "."),

]),

("ship_reembark", 0,
"Do you wish to embark?",
"none", [],
[
    ("reembark_yes", [],
    "Yes.",
    [
        (assign, "$g_player_icon_state", 2),
        (party_set_flags, "p_main_party", 512, 1),
        (party_get_position, pos1, "p_main_party"),
        (map_get_water_position_around_position, 2, pos1, pos6),
        (party_set_position, "p_main_party", pos2),
        (assign, "$g_main_ship_party", "$g_encountered_party"),
        (disable_party, "$g_encountered_party"),
        (change_screen_return),
    ], "."),

    ("reembark_no", [],
    "No.",
    [
        (change_screen_return),
    ], "."),

]),

("center_reports", 0,
"Town Name: {s1}^Econ: {reg7} Prosperity: {reg6}^Rent Income: {reg1} Tariff Income: {reg2}^Wealth: {reg4} Projected: {reg8}^Player weekly income: {reg9}[{reg10}]^Garrison wage: {reg5}^Food Stock: for {reg3} days",
"none", 
[
    (party_get_slot, ":var_0", "$g_encountered_party", slot_party_food_store),
    (call_script, "script_center_get_food_consumption", "$g_encountered_party"),
    (assign, ":var_1", reg0),
    (call_script, "script_calculate_weekly_party_wage", "$g_encountered_party"),
    (assign, reg5, reg0),
    (try_begin),
        (gt, ":var_1", 0),
        (store_div, reg3, ":var_0", ":var_1"),
    (else_try),
        (assign, reg3, 9999),
    (try_end),
    (str_store_party_name, s1, "$g_encountered_party"),
    (party_get_slot, reg1, "$g_encountered_party", slot_center_accumulated_rents),
    (party_get_slot, reg2, "$g_encountered_party", slot_center_accumulated_tariffs),
    (party_get_slot, reg4, "$g_encountered_party", slot_town_wealth),
    (assign, ":var_2", "$g_encountered_party"),
    (assign, ":var_3", reg4),
    (party_get_slot, reg6, "$g_encountered_party", slot_town_prosperity),
    (party_get_slot, reg7, "$g_encountered_party", 290),
    (assign, ":var_4", reg7),
    (val_mul, ":var_4", 4),
    (store_mul, ":var_5", reg6, 14),
    (val_add, ":var_5", 1000),
    (val_add, ":var_5", ":var_4"),
    (try_begin),
        (this_or_next|eq, ":var_2", "p_town_1"),
        (this_or_next|eq, ":var_2", "p_town_5"),
        (this_or_next|eq, ":var_2", "p_town_6"),
        (this_or_next|eq, ":var_2", "p_town_8"),
        (eq, ":var_2", "p_town_10"),
        (val_mul, ":var_5", 12),
        (val_div, ":var_5", 10),
    (try_end),
    (val_add, ":var_3", ":var_5"),
    (val_sub, ":var_3", reg5),
    (val_max, ":var_3", 0),
    (assign, reg8, ":var_3"),
    (assign, ":var_6", 0),
    (party_get_slot, ":var_7", ":var_2", 290),
    (try_begin),
        (party_slot_eq, ":var_2", slot_party_type, 4),
        (try_begin),
            (party_slot_eq, ":var_2", slot_village_state, 0),
            (assign, ":var_6", 600),
            (val_mul, ":var_7", 4),
            (val_add, ":var_6", ":var_7"),
        (try_end),
    (else_try),
        (party_slot_eq, ":var_2", slot_party_type, 2),
        (assign, ":var_6", 600),
        (val_mul, ":var_7", 6),
        (val_add, ":var_6", ":var_7"),
    (else_try),
        (party_slot_eq, ":var_2", slot_party_type, 3),
        (assign, ":var_6", 1200),
        (val_mul, ":var_7", 3),
        (val_add, ":var_6", ":var_7"),
    (try_end),
    (party_get_slot, ":var_8", ":var_2", slot_town_prosperity),
    (store_add, ":var_9", 60, ":var_8"),
    (val_mul, ":var_6", ":var_9"),
    (val_div, ":var_6", 360),
    (assign, reg9, ":var_6"),
    (store_add, reg10, reg9, reg1),
    (val_add, reg10, reg2),
],
[
    ("to_price_and_productions", [],
    "Show prices and productions.",
    [
        (jump_to_menu, "mnu_price_and_production"),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
            (jump_to_menu, "mnu_village"),
        (else_try),
            (jump_to_menu, "mnu_town"),
        (try_end),
    ], "."),

]),

("price_and_production", 0,
"Productions are:^(Note: base/modified by raw materials/modified by materials plus prosperity)^{s1}^^Price factors are:^{s2}",
"none", 
[
    (assign, ":var_0", 0),
    (assign, ":var_1", 0),
    (try_for_range, ":var_2", "p_town_1", "p_castle_1"),
        (call_script, "script_center_get_goods_availability", ":var_2"),
        (val_add, ":var_0", reg0),
    (try_end),
    (try_for_range, ":var_2", "p_village_1", "p_salt_mine"),
        (call_script, "script_center_get_goods_availability", ":var_2"),
        (val_add, ":var_1", reg0),
    (try_end),
    (val_div, ":var_1", 90),
    (val_div, ":var_0", 18),
    (call_script, "script_center_get_goods_availability", "$g_encountered_party"),
    (assign, reg1, ":var_0"),
    (assign, reg2, ":var_1"),
    (try_begin),
        (str_store_string, s1, "str___hardship_index_reg0_avg_towns_reg1_avg_villages_reg2__"),
        (display_message, "@{!}DEBUG - {s1}"),
    (try_end),
    (try_for_range, ":var_3", "itm_spice", "itm_baggage_train"),
        (neg|eq, ":var_3", "itm_pork"),
        (neg|eq, ":var_3", "itm_chicken"),
        (neg|eq, ":var_3", "itm_butter"),
        (neg|eq, ":var_3", "itm_cattle_meat"),
        (neg|eq, ":var_3", "itm_cabbages"),
        (call_script, "script_center_get_production", "$g_encountered_party", ":var_3"),
        (assign, ":var_4", reg0),
        (assign, ":var_5", reg2),
        (assign, ":var_6", reg1),
        (call_script, "script_center_get_consumption", "$g_encountered_party", ":var_3"),
        (assign, ":var_7", reg2),
        (assign, ":var_8", reg1),
        (assign, ":var_9", reg0),
        (store_sub, ":var_10", ":var_3", "itm_spice"),
        (val_add, ":var_10", 301),
        (party_get_slot, ":var_11", "$g_encountered_party", ":var_10"),
        (assign, ":var_12", 0),
        (assign, ":var_13", 0),
        (assign, ":var_14", 0),
        (assign, ":var_15", 0),
        (try_for_range, ":var_2", "p_town_1", "p_salt_mine"),
            (neg|is_between, ":var_2", "p_castle_1", "p_village_1"),
            (val_add, ":var_12", 1),
            (call_script, "script_center_get_production", ":var_2", ":var_3"),
            (assign, ":var_16", reg2),
            (call_script, "script_center_get_consumption", ":var_2", ":var_3"),
            (store_add, ":var_17", reg1, reg2),
            (party_get_slot, ":var_18", ":var_2", ":var_10"),
            (val_add, ":var_13", ":var_18"),
            (val_add, ":var_14", ":var_16"),
            (val_add, ":var_15", ":var_17"),
        (try_end),
        (assign, ":var_19", ":var_14"),
        (assign, ":var_20", ":var_15"),
        (val_div, ":var_13", ":var_12"),
        (val_div, ":var_14", ":var_12"),
        (val_div, ":var_15", ":var_12"),
        (str_store_item_name, s3, ":var_3"),
        (assign, reg1, ":var_5"),
        (assign, reg2, ":var_6"),
        (assign, reg3, ":var_4"),
        (assign, reg4, ":var_11"),
        (assign, reg5, ":var_14"),
        (assign, reg6, ":var_13"),
        (assign, reg7, ":var_7"),
        (assign, reg8, ":var_8"),
        (assign, reg9, ":var_9"),
        (assign, reg10, ":var_15"),
        (item_get_slot, ":var_21", ":var_3", slot_item_production_slot),
        (party_get_slot, ":var_22", "$g_encountered_party", ":var_21"),
        (assign, reg11, ":var_22"),
        (assign, reg12, ":var_19"),
        (assign, reg13, ":var_20"),
        (item_get_slot, ":var_23", ":var_3", slot_item_production_string),
        (str_store_string, s4, ":var_23"),
        (str_store_string, s1, "str___s3_price_=_reg4_calradian_average_reg6_capital_reg11_s4_base_reg1modified_by_raw_material_reg2modified_by_prosperity_reg3_calradian_average_production_base_reg5_total_reg12_consumed_reg7used_as_raw_material_reg8modified_total_reg9_calradian_consumption_base_reg10_total_reg13s1_"),
    (try_end),
],
[
    ("go_back_dot", [],
    "Go back.",
    [
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_type, 4),
            (jump_to_menu, "mnu_village"),
        (else_try),
            (jump_to_menu, "mnu_town"),
        (try_end),
    ], "."),

]),

("town_trade", 0,
"You head towards the marketplace.",
"none", [],
[
    ("assess_prices", 
    [
        (store_faction_of_party, ":var_0", "$current_town"),
        (store_relation, ":var_1", ":var_0", "fac_player_supporters_faction"),
        (ge, ":var_1", 0),
    ],
    "Assess the local prices.",
    [
        (jump_to_menu, "mnu_town_trade_assessment_begin"),
    ], "."),

    ("trade_with_arms_merchant", 
    [
        (party_slot_ge, "$current_town", slot_town_weaponsmith, 1),
    ],
    "Trade with the arms merchant.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_weaponsmith),
        (change_screen_trade, ":var_0"),
    ], "."),

    ("trade_with_armor_merchant", 
    [
        (party_slot_ge, "$current_town", slot_town_armorer, 1),
    ],
    "Trade with the armor merchant.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_armorer),
        (change_screen_trade, ":var_0"),
    ], "."),

    ("trade_with_horse_merchant", 
    [
        (party_slot_ge, "$current_town", slot_town_horse_merchant, 1),
    ],
    "Trade with the horse merchant.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_horse_merchant),
        (change_screen_trade, ":var_0"),
    ], "."),

    ("trade_with_goods_merchant", 
    [
        (party_slot_ge, "$current_town", slot_town_merchant, 1),
    ],
    "Trade with the goods merchant.",
    [
        (party_get_slot, ":var_0", "$current_town", slot_town_merchant),
        (change_screen_trade, ":var_0"),
    ], "."),

    ("sell_all", 
    [
        (troop_get_slot, ":var_0", "trp_loot_pool", 188),
        (troop_get_slot, ":var_1", "trp_loot_pool", 189),
        (gt, ":var_0", 0),
        (ge, ":var_0", ":var_1"),
    ],
    "sell all",
    [
        (call_script, "script_loot_auto_sell"),
        (jump_to_menu, "mnu_town"),
    ], "."),

    ("back_to_town_menu", [],
    "Head back.",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("town_trade_assessment_begin", 0,
"The trade district is bustling with merchants and caravan masters making deals. You overhear several discussions about the prices of trade goods across the local area.",
"none", 
[
    (str_clear, s42),
],
[
    ("continue", [],
    "Listen closely and attempt to work out the best deals",
    [
        (assign, "$auto_enter_town", "$current_town"),
        (assign, "$g_town_assess_trade_goods_after_rest", 1),
        (call_script, "script_get_max_skill_of_player_party", "skl_trade"),
        (val_div, reg0, 2),
        (store_sub, ":var_0", 6, reg0),
        (assign, "$g_last_rest_center", "$current_town"),
        (assign, "$g_last_rest_payment_until", -1),
        (rest_for_hours, ":var_0", 5, 0),
        (change_screen_return),
    ], "."),

    ("back_to_market", [],
    "Go back to the market.",
    [
        (jump_to_menu, "mnu_town_trade"),
    ], "."),

]),

("town_trade_assessment", 512,
"As the party member with the highest trade skill ({reg2}), {reg3?you try to figure out:{s1} tries to figure out} the best goods to trade in. {s2}",
"none", 
[
    (call_script, "script_get_max_skill_of_player_party", "skl_trade"),
    (assign, ":var_0", reg0),
    (assign, ":var_1", reg1),
    (assign, ":var_2", 0),
    (assign, ":var_3", -1),
    (assign, ":var_4", -1),
    (assign, ":var_5", 0),
    (assign, ":var_6", -1),
    (assign, ":var_7", -1),
    (assign, ":var_8", 0),
    (assign, ":var_9", -1),
    (assign, ":var_10", -1),
    (assign, ":var_11", 0),
    (store_sub, ":var_12", "p_castle_1", "p_town_1"),
    (store_sub, ":var_13", "itm_baggage_train", "itm_spice"),
    (store_mul, ":var_14", ":var_12", ":var_13"),
    (val_mul, ":var_14", ":var_0"),
    (val_div, ":var_14", 20),
    (assign, ":var_15", "$g_encountered_party"),
    (try_for_range, ":var_16", 0, ":var_14"),
        (store_random_in_range, ":var_17", "itm_spice", "itm_baggage_train"),
        (store_random_in_range, ":var_18", "p_town_1", "p_castle_1"),
        (assign, ":var_19", 0),
        (try_begin),
            (eq, ":var_17", ":var_3"),
            (eq, ":var_18", ":var_4"),
            (val_add, ":var_19", 1),
        (else_try),
            (eq, ":var_17", ":var_6"),
            (eq, ":var_18", ":var_7"),
            (val_add, ":var_19", 1),
        (else_try),
            (eq, ":var_17", ":var_9"),
            (eq, ":var_18", ":var_10"),
            (val_add, ":var_19", 1),
        (try_end),
        (eq, ":var_19", 0),
        (store_item_value, ":var_20", ":var_17"),
        (assign, "$g_encountered_party", ":var_15"),
        (call_script, "script_game_get_item_buy_price_factor", ":var_17"),
        (store_mul, ":var_21", ":var_20", reg0),
        (val_div, ":var_21", 100),
        (val_max, ":var_21", 1),
        (assign, "$g_encountered_party", ":var_18"),
        (call_script, "script_game_get_item_sell_price_factor", ":var_17"),
        (store_mul, ":var_22", ":var_20", reg0),
        (val_div, ":var_22", 100),
        (val_max, ":var_22", 1),
        (store_sub, ":var_23", ":var_22", ":var_21"),
        (try_begin),
            (gt, ":var_23", ":var_5"),
            (val_add, ":var_2", 1),
            (val_min, ":var_2", 3),
            (assign, ":var_9", ":var_6"),
            (assign, ":var_10", ":var_7"),
            (assign, ":var_11", ":var_8"),
            (assign, ":var_6", ":var_3"),
            (assign, ":var_7", ":var_4"),
            (assign, ":var_8", ":var_5"),
            (assign, ":var_3", ":var_17"),
            (assign, ":var_4", ":var_18"),
            (assign, ":var_5", ":var_23"),
        (else_try),
            (gt, ":var_23", ":var_8"),
            (val_add, ":var_2", 1),
            (val_min, ":var_2", 3),
            (assign, ":var_9", ":var_6"),
            (assign, ":var_10", ":var_7"),
            (assign, ":var_11", ":var_8"),
            (assign, ":var_6", ":var_17"),
            (assign, ":var_7", ":var_18"),
            (assign, ":var_8", ":var_23"),
        (else_try),
            (gt, ":var_23", ":var_11"),
            (val_add, ":var_2", 1),
            (val_min, ":var_2", 3),
            (assign, ":var_9", ":var_17"),
            (assign, ":var_10", ":var_18"),
            (assign, ":var_11", ":var_23"),
        (try_end),
    (try_end),
    (assign, "$g_encountered_party", ":var_15"),
    (str_clear, s3),
    (assign, reg2, ":var_0"),
    (try_begin),
        (eq, ":var_1", "trp_player"),
        (assign, reg3, 1),
    (else_try),
        (assign, reg3, 0),
        (str_store_troop_name, s1, ":var_1"),
    (try_end),
    (try_begin),
        (neg|gt, ":var_2", 0),
        (str_store_string, s2, "@However, {reg3?You are:{s1} is} unable to find any trade goods that would bring a profit."),
    (else_try),
        (try_begin),
            (ge, ":var_9", 0),
            (assign, reg6, ":var_11"),
            (str_store_item_name, s4, ":var_9"),
            (str_store_party_name, s5, ":var_10"),
            (str_store_string, s3, "@^Buying {s4} here and selling it at {s5} would bring a profit of {reg6} denars per item.{s3}"),
        (try_end),
        (try_begin),
            (ge, ":var_6", 0),
            (assign, reg6, ":var_8"),
            (str_store_item_name, s4, ":var_6"),
            (str_store_party_name, s5, ":var_7"),
            (str_store_string, s3, "@^Buying {s4} here and selling it at {s5} would bring a profit of {reg6} denars per item.{s3}"),
        (try_end),
        (try_begin),
            (ge, ":var_3", 0),
            (assign, reg6, ":var_5"),
            (str_store_item_name, s4, ":var_3"),
            (str_store_party_name, s5, ":var_4"),
            (str_store_string, s3, "@^Buying {s4} here and selling it at {s5} would bring a profit of {reg6} denars per item.{s3}"),
        (try_end),
        (str_store_string, s2, "@{reg3?You find:{s1} finds} out the following:^{s3}"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town_trade"),
    ], "."),

]),

("sneak_into_town_suceeded", 0,
"Disguised in the garments of a poor pilgrim, you fool the guards and make your way into the town.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$sneaked_into_town", 1),
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("sneak_into_town_caught", 0,
"As you try to sneak in, one of the guards recognizes you and raises the alarm! You must flee back through the gates before all the guards in the town come down on you!",
"none", 
[
    (assign, "$auto_menu", "mnu_captivity_start_castle_surrender"),
],
[
    ("sneak_caught_fight", [],
    "Try to fight your way out!",
    [
        (assign, "$all_doors_locked", 1),
        (party_get_slot, ":var_0", "$current_town", slot_town_center),
        (modify_visitors_at_site, ":var_0"),
        (reset_visitors),
        (try_begin),
            (this_or_next|eq, "$talk_context", 19),
            (eq, "$talk_context", 18),
            (set_jump_entry, 7),
        (else_try),
            (party_slot_eq, "$current_town", slot_party_type, 3),
            (set_jump_entry, 0),
        (else_try),
            (set_jump_entry, 1),
        (try_end),
        (set_jump_mission, "mt_sneak_caught_fight"),
        (set_passage_menu, "mnu_town"),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("sneak_caught_surrender", [],
    "Surrender.",
    [
        (jump_to_menu, "mnu_captivity_start_castle_surrender"),
    ], "."),

]),

("sneak_into_town_caught_dispersed_guards", 0,
"You drive off the guards and cover your trail before running off, easily losing your pursuers in the maze of streets.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$sneaked_into_town", 1),
        (assign, "$town_entered", 1),
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("sneak_into_town_caught_ran_away", 0,
"You make your way back through the gates and quickly retreat to the safety of the countryside.{s11}",
"none", 
[
    (str_clear, s11),
    (assign, ":var_0", 0),
    (assign, ":var_1", "trp_heroes_end"),
    (try_for_range, ":var_2", "trp_npc_adonja", ":var_1"),
        (try_begin),
            (troop_slot_eq, ":var_2", slot_troop_mission_participation, 4),
            (assign, "$talk_context", 8),
            (assign, reg14, ":var_2"),
            (call_script, "script_setup_troop_meeting", ":var_2", -1),
            (troop_set_slot, ":var_2", slot_troop_mission_participation, -1),
            (troop_get_slot, ":var_3", ":var_2", slot_troop_prisoner_of_party),
            (party_remove_prisoners, ":var_3", ":var_2", 1),
            (troop_set_slot, ":var_2", slot_troop_prisoner_of_party, -1),
            (assign, ":var_1", -1),
        (else_try),
            (troop_slot_eq, ":var_2", slot_troop_mission_participation, 5),
            (str_store_troop_name, s12, ":var_2"),
            (try_begin),
                (eq, ":var_0", 0),
                (str_store_string, s11, "str_s11_unfortunately_s12_was_wounded_and_had_to_be_left_behind"),
            (else_try),
                (str_store_string, s11, "str_s11_also_s12_was_wounded_and_had_to_be_left_behind"),
            (try_end),
            (assign, ":var_0", 1),
        (try_end),
        (troop_set_slot, ":var_2", slot_troop_mission_participation, 0),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$auto_menu", -1),
        (store_encountered_party, "$last_sneak_attempt_town"),
        (store_current_hours, "$last_sneak_attempt_time"),
        (change_screen_return),
    ], "."),

]),

("enemy_offer_ransom_for_prisoner", 0,
"The {s2} offers you a sum of {reg12} denars in silver if you are willing to sell him {s1}.",
"none", 
[
    (call_script, "script_calculate_ransom_amount_for_troop", "$g_ransom_offer_troop"),
    (assign, reg12, reg0),
    (str_store_troop_name, s1, "$g_ransom_offer_troop"),
    (store_troop_faction, ":var_0", "$g_ransom_offer_troop"),
    (str_store_faction_name, s2, ":var_0"),
],
[
    ("ransom_accept", [],
    "Accept the offer.",
    [
        (troop_add_gold, "trp_player", reg12),
        (party_remove_prisoners, "$g_ransom_offer_party", "$g_ransom_offer_troop", 1),
        (call_script, "script_remove_troop_from_prison", "$g_ransom_offer_troop"),
        (try_begin),
            (troop_get_type, ":var_0", "trp_player"),
            (ge, ":var_0", 1),
            (get_achievement_stat, ":var_1", 75, 0),
            (val_add, ":var_1", 1),
            (set_achievement_stat, 75, 0, ":var_1"),
            (eq, ":var_1", 3),
            (unlock_achievement, 75),
        (try_end),
        (change_screen_return),
    ], "."),

    ("ransom_reject", [],
    "Reject the offer.",
    [
        (call_script, "script_change_player_relation_with_troop", "$g_ransom_offer_troop", -4),
        (call_script, "script_change_player_honor", -1),
        (assign, "$g_ransom_offer_rejected", 1),
        (change_screen_return),
    ], "."),

]),

("training_ground", 0,
"You approach a training field where you can practice your martial skills. What kind of training do you want to do?",
"none", 
[
    (store_add, "$g_training_ground_melee_training_scene", "scn_training_ground_ranged_melee_1", "$g_encountered_party"),
    (val_sub, "$g_training_ground_melee_training_scene", "p_training_ground_1"),
    (try_begin),
        (ge, "$g_training_ground_training_count", 3),
        (assign, "$g_training_ground_training_count", 0),
        (rest_for_hours, 1, 5, 1),
        (assign, "$auto_enter_town", "$g_encountered_party"),
        (change_screen_return),
    (try_end),
],
[
    ("camp_trainer", [],
    "Speak with the trainer.",
    [
        (set_jump_mission, "mt_training_ground_trainer_talk"),
        (modify_visitors_at_site, "$g_training_ground_melee_training_scene"),
        (reset_visitors),
        (set_jump_entry, 5),
        (jump_to_scene, "$g_training_ground_melee_training_scene"),
        (change_screen_mission),
        (music_set_situation, 0),
    ], "."),

    ("camp_train_melee", 
    [
        (neg|troop_is_wounded, "trp_player"),
        (call_script, "script_party_count_fit_for_battle", "p_main_party"),
        (gt, reg0, 1),
    ],
    "Sparring practice.",
    [
        (assign, "$g_mt_mode", 1),
        (jump_to_menu, "mnu_training_ground_selection_details_melee_1"),
        (music_set_situation, 0),
    ], "."),

    ("camp_train_archery", [],
    "Ranged weapon practice.",
    [
        (jump_to_menu, "mnu_training_ground_selection_details_ranged_1"),
        (music_set_situation, 0),
    ], "."),

    ("camp_train_mounted", [],
    "Horseback practice.",
    [
        (assign, "$g_mt_mode", 3),
        (jump_to_menu, "mnu_training_ground_selection_details_mounted"),
        (music_set_situation, 0),
    ], "."),

    ("go_to_track", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}Cheat: Go to track.",
    [
        (set_jump_mission, "mt_ai_training"),
        (store_add, ":var_0", "scn_training_ground_horse_track_1", "$g_encountered_party"),
        (val_sub, ":var_0", "p_training_ground_1"),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

    ("go_to_range", 
    [
        (eq, "$cheat_mode", 1),
    ],
    "{!}Cheat: Go to range.",
    [
        (set_jump_mission, "mt_ai_training"),
        (jump_to_scene, "$g_training_ground_melee_training_scene"),
        (change_screen_mission),
    ], "."),

    ("leave", [],
    "Leave.",
    [
        (change_screen_return),
    ], "."),

]),

("training_ground_selection_details_melee_1", 0,
"How many opponents will you go against?",
"none", 
[
    (call_script, "script_write_fit_party_members_to_stack_selection", "p_main_party", 1),
    (troop_get_slot, "$temp", "trp_stack_selection_amounts", 1),
    (assign, "$temp_2", 1),
],
[
    ("camp_train_melee_num_men_1", 
    [
        (ge, "$temp", 1),
    ],
    "One.",
    [
        (assign, "$temp", 1),
        (jump_to_menu, "mnu_training_ground_selection_details_melee_2"),
    ], "."),

    ("camp_train_melee_num_men_2", 
    [
        (ge, "$temp", 2),
    ],
    "Two.",
    [
        (assign, "$temp", 2),
        (jump_to_menu, "mnu_training_ground_selection_details_melee_2"),
    ], "."),

    ("camp_train_melee_num_men_3", 
    [
        (ge, "$temp", 3),
    ],
    "Three.",
    [
        (assign, "$temp", 3),
        (jump_to_menu, "mnu_training_ground_selection_details_melee_2"),
    ], "."),

    ("camp_train_melee_num_men_4", 
    [
        (ge, "$temp", 4),
    ],
    "Four.",
    [
        (assign, "$temp", 4),
        (jump_to_menu, "mnu_training_ground_selection_details_melee_2"),
    ], "."),

    ("go_back_dot", [],
    "Cancel.",
    [
        (jump_to_menu, "mnu_training_ground"),
    ], "."),

]),

("training_ground_selection_details_melee_2", 0,
"Choose your opponent #{reg1}:",
"none", 
[
    (assign, reg1, "$temp_2"),
    (troop_get_slot, "$temp_3", "trp_stack_selection_amounts", slot_troop_relations_begin),
],
[
    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 1),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 1),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 2),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 2),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 3),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 3),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 4),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 4),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 5),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 5),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 6),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 6),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 7),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 7),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 8),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 8),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 9),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 9),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 10),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 10),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 11),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 11),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 12),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 12),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 13),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 13),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 14),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 14),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 15),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 15),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 16),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 16),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 17),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 17),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 18),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 18),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 19),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 19),
    ], "."),

    ("s0", 
    [
        (call_script, "script_cf_training_ground_sub_routine_1_for_melee_details", 20),
    ],
    "{s0}",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", 20),
    ], "."),

    ("training_ground_selection_details_melee_random", [],
    "Choose randomly.",
    [
        (call_script, "script_training_ground_sub_routine_2_for_melee_details", -1),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_training_ground"),
    ], "."),

]),

("training_ground_selection_details_mounted", 0,
"What kind of weapon do you want to train with?",
"none", [],
[
    ("camp_train_mounted_details_1", [],
    "One handed weapon.",
    [
        (call_script, "script_start_training_at_training_ground", 2, 0),
    ], "."),

    ("camp_train_mounted_details_2", [],
    "Polearm.",
    [
        (call_script, "script_start_training_at_training_ground", 4, 0),
    ], "."),

    ("camp_train_mounted_details_3", [],
    "Bow.",
    [
        (call_script, "script_start_training_at_training_ground", 8, 0),
    ], "."),

    ("camp_train_mounted_details_4", [],
    "Thrown weapon.",
    [
        (call_script, "script_start_training_at_training_ground", 10, 0),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_training_ground"),
    ], "."),

]),

("training_ground_selection_details_ranged_1", 0,
"What kind of ranged weapon do you want to train with?",
"none", [],
[
    ("camp_train_ranged_weapon_bow", [],
    "Bow and arrows.",
    [
        (assign, "$g_mt_mode", 2),
        (assign, "$temp", 8),
        (jump_to_menu, "mnu_training_ground_selection_details_ranged_2"),
    ], "."),

    ("camp_train_ranged_weapon_crossbow", [],
    "Crossbow.",
    [
        (assign, "$g_mt_mode", 2),
        (assign, "$temp", 9),
        (jump_to_menu, "mnu_training_ground_selection_details_ranged_2"),
    ], "."),

    ("camp_train_ranged_weapon_thrown", [],
    "Throwing Knives.",
    [
        (assign, "$g_mt_mode", 2),
        (assign, "$temp", 10),
        (jump_to_menu, "mnu_training_ground_selection_details_ranged_2"),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_training_ground"),
    ], "."),

]),

("training_ground_selection_details_ranged_2", 0,
"What range do you want to practice at?",
"none", [],
[
    ("camp_train_ranged_details_1", [],
    "10 yards.",
    [
        (call_script, "script_start_training_at_training_ground", "$temp", 10),
    ], "."),

    ("camp_train_ranged_details_2", [],
    "20 yards.",
    [
        (call_script, "script_start_training_at_training_ground", "$temp", 20),
    ], "."),

    ("camp_train_ranged_details_3", [],
    "30 yards.",
    [
        (call_script, "script_start_training_at_training_ground", "$temp", 30),
    ], "."),

    ("camp_train_ranged_details_4", [],
    "40 yards.",
    [
        (call_script, "script_start_training_at_training_ground", "$temp", 40),
    ], "."),

    ("camp_train_ranged_details_5", 
    [
        (eq, "$g_mt_mode", 2),
    ],
    "50 yards.",
    [
        (call_script, "script_start_training_at_training_ground", "$temp", 50),
    ], "."),

    ("camp_train_ranged_details_6", 
    [
        (eq, "$g_mt_mode", 2),
    ],
    "60 yards.",
    [
        (call_script, "script_start_training_at_training_ground", "$temp", 60),
    ], "."),

    ("camp_train_ranged_details_7", 
    [
        (eq, "$g_mt_mode", 2),
    ],
    "70 yards.",
    [
        (call_script, "script_start_training_at_training_ground", "$temp", 70),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_training_ground"),
    ], "."),

]),

("training_ground_description", 0,
"{s0}",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_scene, "$g_training_ground_training_scene"),
        (change_screen_mission),
    ], "."),

]),

("training_ground_training_result", 512,
"{s7}{s2}",
"none", 
[
    (store_skill_level, ":var_0", "skl_trainer", "trp_player"),
    (store_add, ":var_1", 5, ":var_0"),
    (call_script, "script_write_fit_party_members_to_stack_selection", "p_main_party", 1),
    (str_clear, s2),
    (troop_get_slot, ":var_2", "trp_stack_selection_amounts", 1),
    (troop_get_slot, ":var_3", "trp_stack_selection_amounts", slot_troop_relations_begin),
    (try_begin),
        (gt, "$g_training_ground_training_success_ratio", 0),
        (store_mul, ":var_4", "$g_training_ground_training_success_ratio", "$g_training_ground_training_success_ratio"),
        (try_begin),
            (eq, "$g_training_ground_training_success_ratio", 100),
            (val_mul, ":var_4", 2),
        (try_end),
        (try_begin),
            (eq, "$g_mt_mode", 1),
            (val_div, ":var_4", 2),
        (try_end),
        (val_div, ":var_4", 10),
        (try_begin),
            (gt, ":var_2", 8),
            (val_mul, ":var_4", 3),
            (assign, ":var_5", ":var_2"),
            (convert_to_fixed_point, ":var_5"),
            (store_sqrt, ":var_5", ":var_5"),
            (convert_to_fixed_point, ":var_4"),
            (val_div, ":var_4", ":var_5"),
        (try_end),
        (store_mul, ":var_6", ":var_4", ":var_1"),
        (val_div, ":var_6", 10),
        (party_get_num_companion_stacks, ":var_7", "p_main_party"),
        (store_add, ":var_8", ":var_3", 2),
        (try_for_range, ":var_9", 2, ":var_8"),
            (troop_get_slot, ":var_10", "trp_stack_selection_amounts", ":var_9"),
            (troop_get_slot, ":var_11", "trp_stack_selection_ids", ":var_9"),
            (assign, ":var_12", ":var_7"),
            (try_for_range, ":var_13", 0, ":var_12"),
                (party_stack_get_troop_id, ":var_14", "p_main_party", ":var_13"),
                (eq, ":var_14", ":var_11"),
                (assign, ":var_12", 0),
                (call_script, "script_cf_training_ground_sub_routine_for_training_result", ":var_11", ":var_13", ":var_10", ":var_6"),
                (str_store_troop_name_by_count, s1, ":var_11", ":var_10"),
                (assign, reg1, ":var_10"),
                (str_store_string, s2, "@{s2}^{reg1} {s1} earned {reg0} experience."),
            (try_end),
        (try_end),
        (try_begin),
            (eq, "$g_mt_mode", 1),
            (store_mul, ":var_15", ":var_4", 3),
            (val_div, ":var_15", 2),
            (try_for_range, ":var_16", 0, "$g_training_ground_training_num_enemies"),
                (troop_get_slot, ":var_11", "trp_temp_array_a", ":var_16"),
                (assign, ":var_12", ":var_7"),
                (try_for_range, ":var_13", 0, ":var_12"),
                    (party_stack_get_troop_id, ":var_14", "p_main_party", ":var_13"),
                    (eq, ":var_14", ":var_11"),
                    (assign, ":var_12", 0),
                    (call_script, "script_cf_training_ground_sub_routine_for_training_result", ":var_11", ":var_13", 1, ":var_15"),
                    (str_store_troop_name, s1, ":var_11"),
                    (str_store_string, s2, "@{s2}^{s1} earned an additional {reg0} experience."),
                (try_end),
            (try_end),
        (try_end),
        (try_begin),
            (call_script, "script_cf_training_ground_sub_routine_for_training_result", "trp_player", -1, 1, ":var_4"),
            (str_store_string, s2, "@^You earned {reg0} experience.{s2}"),
        (try_end),
    (try_end),
    (try_begin),
        (eq, "$g_training_ground_training_success_ratio", 0),
        (str_store_string, s7, "@The training didn't go well at all."),
    (else_try),
        (neg|ge, "$g_training_ground_training_success_ratio", 25),
        (str_store_string, s7, "@The training didn't go well at all."),
    (else_try),
        (neg|ge, "$g_training_ground_training_success_ratio", 50),
        (str_store_string, s7, "@The training didn't go very well."),
    (else_try),
        (neg|ge, "$g_training_ground_training_success_ratio", 75),
        (str_store_string, s7, "@The training went quite well."),
    (else_try),
        (neg|ge, "$g_training_ground_training_success_ratio", 99),
        (str_store_string, s7, "@The training went very well."),
    (else_try),
        (str_store_string, s7, "@The training went perfectly."),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_training_ground"),
    ], "."),

]),

("marshall_selection_candidate_ask", 0,
"{s15} will soon select a new marshall for the {s23}. Some of the lords have suggested your name as a likely candidate.",
"none", 
[
    (try_begin),
        (eq, "$g_presentation_marshall_selection_ended", 1),
        (change_screen_return),
    (try_end),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s15, ":var_0"),
    (str_store_faction_name, s23, "$players_kingdom"),
],
[
    ("marshall_candidate_accept", [],
    "Let {s15} learn that you are willing to serve as marshall.",
    [
        (start_presentation, "prsnt_marshall_selection"),
    ], "."),

    ("marshall_candidate_reject", [],
    "Tell everyone that you are too busy these days.",
    [
        (try_begin),
            (eq, "$g_presentation_marshall_selection_max_renown_2_troop", "trp_player"),
            (assign, "$g_presentation_marshall_selection_max_renown_2", "$g_presentation_marshall_selection_max_renown_3"),
            (assign, "$g_presentation_marshall_selection_max_renown_2_troop", "$g_presentation_marshall_selection_max_renown_3_troop"),
        (else_try),
            (assign, "$g_presentation_marshall_selection_max_renown_1", "$g_presentation_marshall_selection_max_renown_2"),
            (assign, "$g_presentation_marshall_selection_max_renown_1_troop", "$g_presentation_marshall_selection_max_renown_2_troop"),
            (assign, "$g_presentation_marshall_selection_max_renown_2", "$g_presentation_marshall_selection_max_renown_3"),
            (assign, "$g_presentation_marshall_selection_max_renown_2_troop", "$g_presentation_marshall_selection_max_renown_3_troop"),
        (try_end),
        (start_presentation, "prsnt_marshall_selection"),
    ], "."),

]),

("captivity_avoid_wilderness", 0,
"Suddenly all the world goes black around you. Many hours later you regain your conciousness and find yourself at the spot you fell. Your enemies must have taken you up for dead and left you there. However, it seems that none of your wounds were lethal, and although you feel awful, you find out you can still walk. You get up and try to look for any other survivors from your party.",
"none", [],
[
]),

("captivity_start_wilderness", 0,
"Stub",
"none", 
[
    (assign, "$g_player_is_captive", 1),
    (try_begin),
        (eq, "$g_player_surrenders", 1),
        (jump_to_menu, "mnu_captivity_start_wilderness_surrender"),
    (else_try),
        (jump_to_menu, "mnu_captivity_start_wilderness_defeat"),
    (try_end),
],
[
]),

("captivity_start_wilderness_surrender", 0,
"Stub",
"none", 
[
    (assign, "$g_player_is_captive", 1),
    (assign, "$auto_menu", -1),
    (assign, "$capturer_party", "$g_encountered_party"),
    (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
],
[
]),

("captivity_start_wilderness_defeat", 0,
"Your enemies take you prisoner.",
"none", 
[
    (assign, "$g_player_is_captive", 1),
    (assign, "$auto_menu", -1),
    (assign, "$capturer_party", "$g_encountered_party"),
    (try_begin),
        (party_stack_get_troop_id, ":var_0", "$g_encountered_party", 0),
        (is_between, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
        (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (store_sub, ":var_1", ":var_0", "trp_npc_adonja"),
        (set_achievement_stat, 7, ":var_1", 1),
    (try_end),
    (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
],
[
]),

("captivity_start_castle_surrender", 0,
"Stub",
"none", 
[
    (assign, "$g_player_is_captive", 1),
    (assign, "$auto_menu", -1),
    (assign, "$capturer_party", "$g_encountered_party"),
    (jump_to_menu, "mnu_captivity_castle_taken_prisoner"),
],
[
]),

("captivity_start_castle_defeat", 0,
"Stub",
"none", 
[
    (assign, "$g_player_is_captive", 1),
    (assign, "$auto_menu", -1),
    (assign, "$capturer_party", "$g_encountered_party"),
    (jump_to_menu, "mnu_captivity_castle_taken_prisoner"),
],
[
]),

("captivity_start_under_siege_defeat", 0,
"Your enemies take you prisoner.",
"none", 
[
    (assign, "$g_player_is_captive", 1),
    (assign, "$auto_menu", -1),
    (try_begin),
        (store_faction_of_party, ":var_0", "$g_enemy_party"),
        (neg|is_between, ":var_0", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (assign, "$capturer_party", "$g_enemy_party"),
        (jump_to_menu, "mnu_captivity_wilderness_taken_prisoner"),
    (else_try),
        (assign, "$capturer_party", "$g_encountered_party"),
        (jump_to_menu, "mnu_captivity_castle_taken_prisoner"),
    (try_end),
],
[
]),

("captivity_wilderness_taken_prisoner", 4096,
"Your enemies take you prisoner.",
"none", 
[
    (set_background_mesh, "mesh_pic_prisoner_wilderness"),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_for_range, ":var_0", "trp_npc_adonja", "trp_kingdom_1_lord"),
            (main_party_has_troop, ":var_0"),
            (store_random_in_range, ":var_1", 0, 100),
            (neg|ge, ":var_1", 30),
            (remove_member_from_party, ":var_0", "p_main_party"),
            (troop_set_slot, ":var_0", slot_troop_occupation, 0),
            (troop_set_slot, ":var_0", slot_troop_playerparty_history, 1),
            (assign, "$last_lost_companion", ":var_0"),
            (store_faction_of_party, ":var_2", "$g_encountered_party"),
            (troop_set_slot, ":var_0", slot_troop_playerparty_history_string, ":var_2"),
            (troop_set_health, ":var_0", 100),
            (store_random_in_range, ":var_3", "p_town_1", "p_castle_1"),
            (troop_set_slot, ":var_0", slot_troop_cur_center, ":var_3"),
            (assign, ":var_4", 1000),
            (try_for_range, ":var_5", "p_town_1", "p_castle_1"),
                (store_faction_of_party, ":var_6", ":var_5"),
                (store_relation, ":var_7", ":var_6", "fac_player_faction"),
                (ge, ":var_7", 0),
                (store_distance_to_party_from_party, ":var_8", ":var_5", "p_main_party"),
                (neg|ge, ":var_8", ":var_4"),
                (assign, ":var_4", ":var_8"),
                (troop_set_slot, ":var_0", slot_troop_cur_center, ":var_5"),
            (try_end),
        (try_end),
        (set_camera_follow_party, "$capturer_party"),
        (assign, "$g_player_is_captive", 1),
        (store_random_in_range, ":var_9", 18, 30),
        (call_script, "script_event_player_captured_as_prisoner"),
        (call_script, "script_stay_captive_for_hours", ":var_9"),
        (assign, "$auto_menu", "mnu_captivity_wilderness_check"),
        (change_screen_return),
    ], "."),

]),

("captivity_wilderness_check", 0,
"stub",
"none", 
[
    (jump_to_menu, "mnu_captivity_end_wilderness_escape"),
],
[
]),

("captivity_end_wilderness_escape", 4096,
"After painful days of being dragged about as a prisoner, you find a chance and escape from your captors!",
"none", 
[
    (play_cue_track, "track_escape"),
    (troop_get_type, ":var_0", "trp_player"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_escape_1_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_escape_1"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$g_player_is_captive", 0),
        (try_begin),
            (party_is_active, "$capturer_party"),
            (party_relocate_near_party, "p_main_party", "$capturer_party", 2),
        (try_end),
        (call_script, "script_set_parties_around_player_ignore_player", 2, 4),
        (assign, "$g_player_icon_state", 0),
        (set_camera_follow_party, "p_main_party"),
        (rest_for_hours, 0, 0, 0),
        (change_screen_return),
    ], "."),

]),

("captivity_castle_taken_prisoner", 0,
"You are quickly surrounded by guards who take away your weapons. With curses and insults, they throw you into the dungeon where you must while away the miserable days of your captivity.",
"none", 
[
    (troop_get_type, ":var_0", "trp_player"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_prisoner_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_prisoner_man"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$g_player_is_captive", 1),
        (store_random_in_range, ":var_0", 16, 22),
        (call_script, "script_event_player_captured_as_prisoner"),
        (call_script, "script_stay_captive_for_hours", ":var_0"),
        (assign, "$auto_menu", "mnu_captivity_castle_check"),
        (change_screen_return),
    ], "."),

]),

("captivity_rescue_lord_taken_prisoner", 0,
"You remain in disguise for as long as possible before revealing yourself. The guards are outraged and beat you savagely before throwing you back into the cell for God knows how long...",
"none", 
[
    (troop_get_type, ":var_0", "trp_player"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_prisoner_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_prisoner_man"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$g_player_is_captive", 1),
        (store_random_in_range, ":var_0", 16, 22),
        (call_script, "script_event_player_captured_as_prisoner"),
        (call_script, "script_stay_captive_for_hours", ":var_0"),
        (assign, "$auto_menu", "mnu_captivity_castle_check"),
        (change_screen_return),
    ], "."),

]),

("captivity_castle_check", 0,
"stub",
"none", 
[
    (store_random_in_range, reg7, 0, 10),
    (try_begin),
        (party_is_active, "$capturer_party"),
        (store_faction_of_party, ":var_0", "$capturer_party"),
        (is_between, ":var_0", "fac_player_supporters_faction", "fac_kingdoms_end"),
        (store_relation, ":var_1", ":var_0", "fac_player_faction"),
        (ge, ":var_1", 0),
        (jump_to_menu, "mnu_captivity_end_exchanged_with_prisoner"),
    (else_try),
        (neg|ge, reg7, 4),
        (store_character_level, ":var_2", "trp_player"),
        (store_mul, "$player_ransom_amount", ":var_2", 50),
        (val_add, "$player_ransom_amount", 100),
        (store_troop_gold, reg3, "trp_player"),
        (store_div, ":var_3", reg3, 20),
        (val_add, "$player_ransom_amount", ":var_3"),
        (gt, reg3, "$player_ransom_amount"),
        (jump_to_menu, "mnu_captivity_end_propose_ransom"),
    (else_try),
        (neg|ge, reg7, 7),
        (jump_to_menu, "mnu_captivity_end_exchanged_with_prisoner"),
    (else_try),
        (jump_to_menu, "mnu_captivity_castle_remain"),
    (try_end),
],
[
]),

("captivity_end_exchanged_with_prisoner", 0,
"After days of imprisonment, you are finally set free when your captors exchange you with another prisoner.",
"none", 
[
    (play_cue_track, "track_escape"),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$g_player_is_captive", 0),
        (try_begin),
            (party_is_active, "$capturer_party"),
            (party_relocate_near_party, "p_main_party", "$capturer_party", 2),
        (try_end),
        (call_script, "script_set_parties_around_player_ignore_player", 2, 12),
        (assign, "$g_player_icon_state", 0),
        (set_camera_follow_party, "p_main_party"),
        (rest_for_hours, 0, 0, 0),
        (change_screen_return),
    ], "."),

]),

("captivity_end_propose_ransom", 0,
"You spend long hours in the sunless dank of the dungeon, more than you can count. Suddenly one of your captors enters your cell with an offer; he proposes to free you in return for {reg5} denars of your hidden wealth. You decide to...",
"none", 
[
    (assign, reg5, "$player_ransom_amount"),
],
[
    ("captivity_end_ransom_accept", 
    [
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", "$player_ransom_amount"),
    ],
    "Accept the offer.",
    [
        (play_cue_track, "track_escape"),
        (assign, "$g_player_is_captive", 0),
        (troop_remove_gold, "trp_player", "$player_ransom_amount"),
        (try_begin),
            (party_is_active, "$capturer_party"),
            (party_relocate_near_party, "p_main_party", "$capturer_party", 1),
        (try_end),
        (call_script, "script_set_parties_around_player_ignore_player", 2, 6),
        (assign, "$g_player_icon_state", 0),
        (set_camera_follow_party, "p_main_party"),
        (rest_for_hours, 0, 0, 0),
        (change_screen_return),
    ], "."),

    ("captivity_end_ransom_deny", [],
    "Refuse him, wait for something better.",
    [
        (assign, "$g_player_is_captive", 1),
        (store_random_in_range, reg8, 16, 22),
        (call_script, "script_stay_captive_for_hours", reg8),
        (assign, "$auto_menu", "mnu_captivity_castle_check"),
        (change_screen_return),
    ], "."),

]),

("captivity_castle_remain", 4608,
"More days pass in the darkness of your cell. You get through them as best you can, enduring the kicks and curses of the guards, watching your underfed body waste away more and more...",
"none", 
[
    (troop_get_type, ":var_0", "trp_player"),
    (try_begin),
        (ge, ":var_0", 1),
        (set_background_mesh, "mesh_pic_prisoner_fem"),
    (else_try),
        (set_background_mesh, "mesh_pic_prisoner_man"),
    (try_end),
    (store_random_in_range, ":var_1", 16, 22),
    (call_script, "script_stay_captive_for_hours", ":var_1"),
    (assign, "$auto_menu", "mnu_captivity_castle_check"),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$g_player_is_captive", 1),
        (change_screen_return),
    ], "."),

]),

("kingdom_army_quest_report_to_army", 4096,
"{s8} sends word that he wishes you to join {reg4?her:his} new military campaign. You need to bring at least {reg13} troops to the army, and are instructed to raise more men with all due haste if you do not have enough.",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (quest_get_slot, ":var_0", "qst_report_to_army", 2),
    (quest_get_slot, ":var_1", "qst_report_to_army", 10),
    (call_script, "script_get_information_about_troops_position", ":var_0", 0),
    (str_clear, s9),
    (try_begin),
        (eq, reg0, 1),
        (str_store_string, s9, 1),
    (try_end),
    (str_store_troop_name, s8, ":var_0"),
    (assign, reg13, ":var_1"),
    (troop_get_type, reg4, ":var_0"),
],
[
    ("continue", [],
    "Continue...",
    [
        (quest_get_slot, ":var_0", "qst_report_to_army", 2),
        (quest_get_slot, ":var_1", "qst_report_to_army", 10),
        (str_store_troop_name_link, s13, ":var_0"),
        (assign, reg13, ":var_1"),
        (setup_quest_text, "qst_report_to_army"),
        (str_store_string, s2, "@{s13} asked you to report to him with at least {reg13} troops."),
        (call_script, "script_start_quest", "qst_report_to_army", ":var_0"),
        (call_script, "script_report_quest_troop_positions", "qst_report_to_army", ":var_0", 3),
        (change_screen_return),
    ], "."),

]),

("kingdom_army_quest_messenger", 4096,
"{s8} sends word that he wishes to speak with you about a task he needs performed. He requests you to come and see him as soon as possible.",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_marshall),
    (str_store_troop_name, s8, ":var_0"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("kingdom_army_quest_join_siege_order", 4096,
"{s8} sends word that you are to join the siege of {s9} in preparation for a full assault. Your troops are to take {s9} at all costs.",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_marshall),
    (quest_get_slot, ":var_1", "qst_join_siege_with_army", 1),
    (str_store_troop_name, s8, ":var_0"),
    (str_store_party_name, s9, ":var_1"),
],
[
    ("continue", [],
    "Continue...",
    [
        (call_script, "script_end_quest", "qst_follow_army"),
        (quest_get_slot, ":var_0", "qst_join_siege_with_army", 1),
        (faction_get_slot, ":var_1", "$players_kingdom", slot_faction_marshall),
        (str_store_troop_name_link, s13, ":var_1"),
        (str_store_party_name_link, s14, ":var_0"),
        (setup_quest_text, "qst_join_siege_with_army"),
        (str_store_string, s2, "@{s13} ordered you to join the assault against {s14}."),
        (call_script, "script_start_quest", "qst_join_siege_with_army", ":var_1"),
        (change_screen_return),
    ], "."),

]),

("kingdom_army_follow_failed", 4096,
"You have failed to follow {s8}. The marshal assumes that you were otherwise engaged, but would have appreciated your support.",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_marshall),
    (str_store_troop_name, s8, ":var_0"),
    (call_script, "script_abort_quest", "qst_follow_army", 1),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("invite_player_to_faction_without_center", 4096,
"You receive an offer of vassalage!^^ {s8} of the {s9} has sent a royal herald to bring you an invititation in his own hand. You would be granted the honor of becoming a vassal {reg63?lord:lady} of the {s9}, and in return {s8} asks you to swear an oath of homage to him and fight in his military campaigns, although he offers you no lands or titles. He will surely be offended if you do not take the offer...",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, "$g_invite_faction_lord", "$g_invite_faction", slot_faction_leader),
    (str_store_troop_name, s8, "$g_invite_faction_lord"),
    (str_store_faction_name, s9, "$g_invite_faction"),
    (call_script, "script_gender_to_reg63"),
],
[
    ("faction_accept", [],
    "Accept!",
    [
        (str_store_troop_name, s1, "$g_invite_faction_lord"),
        (setup_quest_text, "qst_join_faction"),
        (str_store_troop_name_link, s3, "$g_invite_faction_lord"),
        (str_store_faction_name_link, s4, "$g_invite_faction"),
        (quest_set_slot, "qst_join_faction", 6, "$g_invite_faction_lord"),
        (quest_set_slot, "qst_join_faction", 23, 30),
        (quest_set_slot, "qst_join_faction", 26, 0),
        (str_store_string, s2, "@Find and speak with {s3} of the {s4} to give him your oath of homage."),
        (call_script, "script_start_quest", "qst_join_faction", "$g_invite_faction_lord"),
        (call_script, "script_report_quest_troop_positions", "qst_join_faction", "$g_invite_faction_lord", 3),
        (jump_to_menu, "mnu_invite_player_to_faction_accepted"),
    ], "."),

    ("faction_reject", [],
    "Decline the invitation.",
    [
        (call_script, "script_change_player_relation_with_troop", "$g_invite_faction_lord", -3),
        (call_script, "script_change_player_relation_with_faction", "$g_invite_faction", -10),
        (assign, "$g_invite_faction", 0),
        (assign, "$g_invite_faction_lord", 0),
        (assign, "$g_invite_offered_center", 0),
        (change_screen_return),
    ], "."),

]),

("invite_player_to_faction", 4096,
"You receive an offer of vassalage!^^ {s8} of the {s9} has sent a royal herald to bring you an invititation in his own hand. You would be granted the honor of becoming a vassal {reg63?lord:lady} of the {s9}, and in return {s8} asks you to swear an oath of homage to him and fight in his military campaigns, offering you the fief of {s2} for your loyal service. He will surely be offended if you do not take the offer...",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (faction_get_slot, "$g_invite_faction_lord", "$g_invite_faction", slot_faction_leader),
    (str_store_troop_name, s8, "$g_invite_faction_lord"),
    (str_store_faction_name, s9, "$g_invite_faction"),
    (str_store_party_name, s2, "$g_invite_offered_center"),
],
[
    ("faction_accept", [],
    "Accept!",
    [
        (str_store_troop_name, s1, "$g_invite_faction_lord"),
        (setup_quest_text, "qst_join_faction"),
        (str_store_troop_name_link, s3, "$g_invite_faction_lord"),
        (str_store_faction_name_link, s4, "$g_invite_faction"),
        (quest_set_slot, "qst_join_faction", 6, "$g_invite_faction_lord"),
        (quest_set_slot, "qst_join_faction", 23, 30),
        (str_store_string, s2, "@Find and speak with {s3} of the {s4} to give him your oath of homage."),
        (call_script, "script_start_quest", "qst_join_faction", "$g_invite_faction_lord"),
        (call_script, "script_report_quest_troop_positions", "qst_join_faction", "$g_invite_faction_lord", 3),
        (jump_to_menu, "mnu_invite_player_to_faction_accepted"),
    ], "."),

    ("faction_reject", [],
    "Decline the invitation.",
    [
        (call_script, "script_change_player_relation_with_troop", "$g_invite_faction_lord", -3),
        (assign, "$g_invite_faction", 0),
        (assign, "$g_invite_faction_lord", 0),
        (assign, "$g_invite_offered_center", 0),
        (change_screen_return),
    ], "."),

]),

("invite_player_to_faction_accepted", 0,
"In order to become a vassal, you must swear an oath of homage to {s3}. You shall have to find him and give him your oath in person. {s5}",
"none", 
[
    (call_script, "script_get_information_about_troops_position", "$g_invite_faction_lord", 0),
    (str_store_troop_name, s3, "$g_invite_faction_lord"),
    (str_store_string, s5, "@{!}{s1}"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("question_peace_offer", 0,
"You Receive a Peace Offer^^The {s1} offers you a peace agreement. What is your answer?",
"none", 
[
    (str_store_faction_name, s1, "$g_notification_menu_var1"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "$g_notification_menu_var1", pos0),
],
[
    ("peace_offer_accept", [],
    "Accept",
    [
        (call_script, "script_diplomacy_start_peace_between_kingdoms", "fac_player_supporters_faction", "$g_notification_menu_var1", 1),
        (change_screen_return),
    ], "."),

    ("peace_offer_reject", [],
    "Reject",
    [
        (call_script, "script_change_player_relation_with_faction", "$g_notification_menu_var1", -5),
        (change_screen_return),
    ], "."),

]),

("notification_truce_expired", 0,
"Truce Has Expired^^The truce between the {s1} and the {s2} has expired.",
"none", 
[
    (str_store_faction_name, s1, "$g_notification_menu_var1"),
    (str_store_faction_name, s2, "$g_notification_menu_var2"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue",
    [
        (change_screen_return),
    ], "."),

]),

("notification_feast_quest_expired", 0,
"{s10}",
"none", 
[
    (str_store_string, s10, "str_feast_quest_expired"),
],
[
    ("continue", [],
    "Continue",
    [
        (change_screen_return),
    ], "."),

]),

("notification_sortie_possible", 0,
"Enemy Sighted: Enemies have been sighted outside the walls of {s4}, and {s5} and others are preparing for a sortie. You may join them if you wish.",
"none", 
[
    (str_store_party_name, s4, "$g_notification_menu_var1"),
    (party_stack_get_troop_id, ":var_0", "$g_notification_menu_var2", 0),
    (str_store_troop_name, s5, ":var_0"),
],
[
    ("continue", [],
    "Continue",
    [
        (change_screen_return),
    ], "."),

]),

("notification_casus_belli_expired", 0,
"Kingdom Fails to Respond^^The {s1} has not responded to the {s2}'s provocations, and {s3} suffers a loss of face among {reg4?her:his} more bellicose subjects...^",
"none", 
[
    (str_store_faction_name, s1, "$g_notification_menu_var1"),
    (str_store_faction_name, s2, "$g_notification_menu_var2"),
    (faction_get_slot, ":var_0", "$g_notification_menu_var1", slot_faction_leader),
    (str_store_troop_name, s3, ":var_0"),
    (troop_get_type, reg4, ":var_0"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue",
    [
        (call_script, "script_faction_follows_controversial_policy", "$g_notification_menu_var1", 81),
        (change_screen_return),
    ], "."),

]),

("notification_lord_defects", 0,
"Defection: {s4} has abandoned the {s5} and joined the {s7}, taking {reg4?her:his} fiefs with him",
"none", 
[
    (assign, ":var_0", "$g_notification_menu_var1"),
    (assign, ":var_1", "$g_notification_menu_var2"),
    (str_store_troop_name, s4, ":var_0"),
    (str_store_faction_name, s5, ":var_1"),
    (store_troop_faction, ":var_2", ":var_0"),
    (str_store_faction_name, s7, ":var_2"),
    (troop_get_type, reg4, ":var_0"),
],
[
    ("continue", [],
    "Continue",
    [
        (change_screen_return),
    ], "."),

]),

("notification_treason_indictment", 0,
"Treason Indictment^^{s9}",
"none", 
[
    (assign, ":var_0", "$g_notification_menu_var1"),
    (assign, ":var_1", "$g_notification_menu_var2"),
    (faction_get_slot, ":var_2", ":var_1", slot_faction_leader),
    (try_begin),
        (eq, ":var_0", "trp_player"),
        (str_store_troop_name, s7, ":var_2"),
        (str_store_string, s9, "str_you_have_been_indicted_for_treason_to_s7_your_properties_have_been_confiscated_and_you_would_be_well_advised_to_flee_for_your_life"),
    (else_try),
        (str_store_troop_name, s4, ":var_0"),
        (str_store_faction_name, s5, ":var_1"),
        (str_store_troop_name, s6, ":var_2"),
        (troop_get_type, reg4, ":var_0"),
        (store_troop_faction, ":var_3", ":var_0"),
        (try_begin),
            (is_between, ":var_3", "fac_player_supporters_faction", "fac_kingdoms_end"),
            (str_store_faction_name, s10, ":var_3"),
            (str_store_string, s11, "str_with_the_s10"),
        (else_try),
            (str_store_string, s11, "str_outside_calradia"),
        (try_end),
        (str_store_string, s9, "str_by_order_of_s6_s4_of_the_s5_has_been_indicted_for_treason_the_lord_has_been_stripped_of_all_reg4herhis_properties_and_has_fled_for_reg4herhis_life_he_is_rumored_to_have_gone_into_exile_s11"),
    (try_end),
],
[
    ("continue", [],
    "Continue",
    [
        (change_screen_return),
    ], "."),

]),

("notification_border_incident", 0,
"Border incident^^Word reaches you that {s9}. Though you don't know whether or not the rumors are true, you do know one thing -- this seemingly minor incident has raised passions among the {s4}, making it easier for them to go to war against the {s3}, if they want it...",
"none", 
[
    (assign, ":var_0", "$g_notification_menu_var1"),
    (assign, ":var_1", "$g_notification_menu_var2"),
    (store_faction_of_party, ":var_2", ":var_0"),
    (try_begin),
        (eq, ":var_1", -1),
        (party_get_slot, ":var_3", ":var_0", slot_center_original_faction),
        (try_begin),
            (this_or_next|eq, ":var_3", ":var_2"),
            (neg|faction_slot_eq, ":var_3", slot_faction_state, 0),
            (party_get_slot, ":var_3", ":var_0", slot_center_ex_faction),
        (try_end),
        (str_store_party_name, s1, ":var_0"),
        (str_store_faction_name, s3, ":var_2"),
        (str_store_faction_name, s4, ":var_3"),
        (faction_get_slot, ":var_4", ":var_3", slot_faction_leader),
        (str_store_troop_name, s5, ":var_4"),
        (str_store_string, s9, "str_local_notables_from_s1_a_village_claimed_by_the_s4_have_been_mistreated_by_their_overlords_from_the_s3_and_petition_s5_for_protection"),
        (display_log_message, "@There has been an alleged border incident: {s9}"),
        (call_script, "script_add_log_entry", 75, ":var_0", -1, -1, ":var_2"),
    (else_try),
        (store_faction_of_party, ":var_3", ":var_1"),
        (str_store_party_name, s1, ":var_0"),
        (str_store_party_name, s2, ":var_1"),
        (store_random_in_range, ":var_5", 0, 3),
        (try_begin),
            (eq, ":var_5", 0),
            (str_store_string, s9, "str_villagers_from_s1_stole_some_cattle_from_s2"),
            (display_log_message, "@There has been an alleged border incident: {s9}"),
            (call_script, "script_add_log_entry", 72, ":var_0", ":var_1", -1, ":var_2"),
        (else_try),
            (eq, ":var_5", 1),
            (str_store_string, s9, "str_villagers_from_s1_abducted_a_woman_from_a_prominent_family_in_s2_to_marry_one_of_their_boys"),
            (display_log_message, "@There has been an alleged border incident: {s9}"),
            (call_script, "script_add_log_entry", 73, ":var_0", ":var_1", -1, ":var_2"),
        (else_try),
            (eq, ":var_5", 2),
            (str_store_string, s9, "str_villagers_from_s1_killed_some_farmers_from_s2_in_a_fight_over_the_diversion_of_a_stream"),
            (display_log_message, "@There has been an alleged border incident: {s9}"),
            (call_script, "script_add_log_entry", 74, ":var_0", ":var_1", -1, ":var_2"),
        (try_end),
    (try_end),
    (str_store_faction_name, s3, ":var_2"),
    (str_store_faction_name, s4, ":var_3"),
    (store_add, ":var_6", ":var_2", 130),
    (val_sub, ":var_6", "fac_player_supporters_faction"),
    (faction_set_slot, ":var_3", ":var_6", 30),
],
[
    ("continue", [],
    "Continue",
    [
        (change_screen_return),
    ], "."),

]),

("notification_player_faction_active", 0,
"You now possess land in your name, without being tied to any kingdom. This makes you a monarch in your own right, with your court temporarily located at {s12}. However, the other kings in Pendor will at first consider you a threat, for if any upstart warlord can grab a throne, then their own legitimacy is called into question.^^You may find it desirable at this time to pledge yourself to an existing kingdom. If you want to continue as a sovereign monarch, then your first priority should be to establish an independent right to rule. You can establish your right to rule through several means -- marrying into a high-born family, recruiting new lords, governing your lands, treating with other kings, or dispatching your companions on missions.^^At any rate, your first step should be to appoint a chief minister from among your companions, to handle affairs of state. Different companions have different capabilities.^You may appoint new ministers from time to time. You may also change the location of your court, by speaking to the minister.",
"none", 
[
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "fac_player_supporters_faction", pos0),
    (unlock_achievement, 52),
    (play_track, "track_coronation"),
    (try_for_range, ":var_0", "p_town_1", "p_village_1"),
        (neg|ge, "$g_player_court", "p_town_1"),
        (store_faction_of_party, ":var_1", ":var_0"),
        (eq, ":var_1", "fac_player_supporters_faction"),
        (assign, "$g_player_court", ":var_0"),
        (try_begin),
            (troop_get_slot, ":var_2", "trp_player", slot_troop_spouse),
            (is_between, ":var_2", "trp_knight_1_1_wife", "trp_heroes_end"),
            (troop_set_slot, ":var_2", slot_troop_cur_center, "$g_player_court"),
        (try_end),
        (str_store_party_name, s12, "$g_player_court"),
    (try_end),
],
[
    ("appoint_spouse", 
    [
        (troop_slot_ge, "trp_player", slot_troop_spouse, 1),
        (troop_get_slot, ":var_0", "trp_player", slot_troop_spouse),
        (neg|troop_slot_eq, ":var_0", slot_troop_occupation, 2),
        (str_store_troop_name, s10, ":var_0"),
    ],
    "Appoint your wife, {s10}...",
    [
        (troop_get_slot, ":var_0", "trp_player", slot_troop_spouse),
        (assign, "$g_player_minister", ":var_0"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_adonja", 
    [
        (main_party_has_troop, "trp_npc_adonja"),
        (str_store_troop_name, s10, "trp_npc_adonja"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_adonja"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_leslie", 
    [
        (main_party_has_troop, "trp_npc_leslie"),
        (str_store_troop_name, s10, "trp_npc_leslie"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_leslie"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_ansen", 
    [
        (main_party_has_troop, "trp_npc_ansen"),
        (str_store_troop_name, s10, "trp_npc_ansen"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_ansen"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_riva", 
    [
        (main_party_has_troop, "trp_npc_riva"),
        (str_store_troop_name, s10, "trp_npc_riva"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_riva"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_kassim", 
    [
        (main_party_has_troop, "trp_npc_kassim"),
        (str_store_troop_name, s10, "trp_npc_kassim"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_kassim"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_lethaldiran", 
    [
        (main_party_has_troop, "trp_npc_lethaldiran"),
        (str_store_troop_name, s10, "trp_npc_lethaldiran"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_lethaldiran"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_jocelyn", 
    [
        (main_party_has_troop, "trp_npc_jocelyn"),
        (str_store_troop_name, s10, "trp_npc_jocelyn"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_jocelyn"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_alistair", 
    [
        (main_party_has_troop, "trp_npc_alistair"),
        (str_store_troop_name, s10, "trp_npc_alistair"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_alistair"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_rayne", 
    [
        (main_party_has_troop, "trp_npc_rayne"),
        (str_store_troop_name, s10, "trp_npc_rayne"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_rayne"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_julia", 
    [
        (main_party_has_troop, "trp_npc_julia"),
        (str_store_troop_name, s10, "trp_npc_julia"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_julia"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_frederick", 
    [
        (main_party_has_troop, "trp_npc_frederick"),
        (str_store_troop_name, s10, "trp_npc_frederick"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_frederick"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_ediz", 
    [
        (main_party_has_troop, "trp_npc_ediz"),
        (str_store_troop_name, s10, "trp_npc_ediz"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_ediz"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_sara", 
    [
        (main_party_has_troop, "trp_npc_sara"),
        (str_store_troop_name, s10, "trp_npc_sara"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_sara"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_donavan", 
    [
        (main_party_has_troop, "trp_npc_donavan"),
        (str_store_troop_name, s10, "trp_npc_donavan"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_donavan"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_diev", 
    [
        (main_party_has_troop, "trp_npc_diev"),
        (str_store_troop_name, s10, "trp_npc_diev"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_diev"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_alyssa", 
    [
        (main_party_has_troop, "trp_npc_alyssa"),
        (str_store_troop_name, s10, "trp_npc_alyssa"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_alyssa"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_roland", 
    [
        (main_party_has_troop, "trp_npc_roland"),
        (str_store_troop_name, s10, "trp_npc_roland"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_roland"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_kaverra", 
    [
        (main_party_has_troop, "trp_npc_kaverra"),
        (str_store_troop_name, s10, "trp_npc_kaverra"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_kaverra"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_sigismund", 
    [
        (main_party_has_troop, "trp_npc_sigismund"),
        (str_store_troop_name, s10, "trp_npc_sigismund"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_sigismund"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_npc_boadice", 
    [
        (main_party_has_troop, "trp_npc_boadice"),
        (str_store_troop_name, s10, "trp_npc_boadice"),
    ],
    "Appoint {s10}",
    [
        (assign, "$g_player_minister", "trp_npc_boadice"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

    ("appoint_default", [],
    "Appoint a prominent citizen from the area...",
    [
        (assign, "$g_player_minister", "trp_temporary_minister"),
        (troop_set_faction, "trp_temporary_minister", "fac_player_supporters_faction"),
        (jump_to_menu, "mnu_minister_confirm"),
    ], "."),

]),

("minister_confirm", 0,
"{s9}can be found at your court in {s12}. You should consult periodically, to avoid the accumulation of unresolved issues that may sap your authority...",
"none", 
[
    (try_begin),
        (eq, "$players_kingdom_name_set", 1),
        (change_screen_return),
    (try_end),
    (try_begin),
        (eq, "$g_player_minister", "trp_temporary_minister"),
        (str_store_string, s9, "str_your_new_minister_"),
    (else_try),
        (str_store_troop_name, s10, "$g_player_minister"),
        (str_store_string, s9, "str_s10_is_your_new_minister_and_"),
    (try_end),
    (try_begin),
        (main_party_has_troop, "$g_player_minister"),
        (remove_member_from_party, "$g_player_minister", "p_main_party"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (start_presentation, "prsnt_name_kingdom"),
    ], "."),

]),

("auto_name_stronghold", 4096,
"stub",
"none", 
[
    (try_begin),
        (eq, "$menu_control", -1),
        (start_presentation, "prsnt_name_stronghold"),
        (assign, "$menu_control", 0),
    (else_try),
        (change_screen_return),
    (try_end),
],
[
]),

("auto_name_order", 4096,
"Long live the {s2} order and its faithful {s3} and {s4}, established on {s60} by the wise and honorable {s5}!",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (str_store_faction_name, s2, "fac_player_knights"),
    (str_store_troop_name_plural, s3, "trp_player_knight"),
    (str_store_troop_name_plural, s4, "trp_player_sergeant"),
    (store_current_hours, ":var_0"),
    (str_store_date, s60, ":var_0"),
    (str_store_troop_name, s5, "trp_player"),
    (try_begin),
        (eq, "$menu_control", -1),
        (start_presentation, "prsnt_name_order"),
        (assign, "$menu_control", 0),
    (else_try),
        (play_sound, "snd_achievement_screen_fanfare"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("upgrade_screen", 4096,
"stub",
"none", 
[
    (try_begin),
        (eq, "$menu_control", 0),
        (call_script, "script_prepare_dummy_and_wardrobe_for_upgrade", "$g_pop_upgrade_troop", "$g_pop_upgrade_type"),
        (try_begin),
            (eq, "$g_pop_upgrade_troop", "trp_player_knight"),
            (assign, "$g_pop_upgrade_troop_dummy", "trp_player_knight_dummy"),
        (else_try),
            (assign, "$g_pop_upgrade_troop_dummy", "trp_player_sergeant_dummy"),
        (try_end),
        (change_screen_equip_other, "$g_pop_upgrade_troop_dummy"),
        (assign, "$menu_control", 1),
    (else_try),
        (eq, "$menu_control", 1),
        (set_player_troop, "trp_player"),
        (assign, "$pop_teleport_player_to_pos59", 1),
        (assign, "$town_entered", 1),
        (call_script, "script_enter_court", "$current_town"),
        (assign, "$menu_control", 2),
    (else_try),
        (jump_to_menu, "mnu_town"),
    (try_end),
],
[
]),

("auto_grandmaster", 0,
"{!}This menu automatically returns to caller.",
"none", 
[
    (try_begin),
        (eq, "$menu_control", 0),
        (party_clear, "p_temp_party"),
        (party_add_members, "p_temp_party", "$g_talk_troop", 30),
        (store_sub, ":var_0", "$g_talk_troop", "trp_dragon_knight"),
        (val_add, ":var_0", "trp_dragon_drake"),
        (party_add_members, "p_temp_party", ":var_0", 50),
        (change_screen_exchange_with_party, "p_temp_party"),
        (assign, "$menu_control", 2),
    (else_try),
        (change_screen_map),
    (try_end),
],
[
]),

("notification_court_lost", 0,
"{s12}",
"none", 
[
    (try_begin),
        (is_between, "$g_player_court", "p_town_1", "p_salt_mine"),
        (str_store_party_name, s10, "$g_player_court"),
        (str_store_party_name, s11, "$g_player_court"),
    (else_try),
        (str_store_string, s10, "str_your_previous_court_some_time_ago"),
        (str_store_string, s11, "str_your_previous_court_some_time_ago"),
    (try_end),
    (assign, "$g_player_court", -1),
    (str_store_string, s14, "str_after_to_the_fall_of_s11_your_court_has_nowhere_to_go"),
    (try_begin),
        (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, 2),
        (str_store_string, s14, "str_as_you_no_longer_maintain_an_independent_kingdom_you_no_longer_maintain_a_court"),
    (try_end),
    (try_for_range, ":var_0", "p_town_1", "p_village_1"),
        (eq, "$g_player_court", -1),
        (store_faction_of_party, ":var_1", ":var_0"),
        (eq, ":var_1", "fac_player_supporters_faction"),
        (neg|party_slot_ge, ":var_0", slot_town_lord, "trp_npc_adonja"),
        (assign, "$g_player_court", ":var_0"),
        (try_begin),
            (troop_get_slot, ":var_2", "trp_player", slot_troop_spouse),
            (is_between, ":var_2", "trp_knight_1_1_wife", "trp_heroes_end"),
            (troop_set_slot, ":var_2", slot_troop_cur_center, "$g_player_court"),
            (str_store_party_name, s11, "$g_player_court"),
        (try_end),
        (str_store_string, s14, "str_due_to_the_fall_of_s10_your_court_has_been_relocated_to_s12"),
    (try_end),
    (try_for_range, ":var_0", "p_town_1", "p_village_1"),
        (eq, "$g_player_court", -1),
        (store_faction_of_party, ":var_1", ":var_0"),
        (eq, ":var_1", "fac_player_supporters_faction"),
        (assign, "$g_player_court", ":var_0"),
        (try_begin),
            (troop_get_slot, ":var_2", "trp_player", slot_troop_spouse),
            (is_between, ":var_2", "trp_knight_1_1_wife", "trp_heroes_end"),
            (troop_set_slot, ":var_2", slot_troop_cur_center, "$g_player_court"),
        (try_end),
        (party_get_slot, ":var_3", ":var_0", slot_town_lord),
        (str_store_party_name, s11, "$g_player_court"),
        (str_store_troop_name, s9, ":var_3"),
        (str_store_string, s14, "str_after_to_the_fall_of_s10_your_faithful_vassal_s9_has_invited_your_court_to_s11_"),
    (try_end),
    (try_begin),
        (faction_slot_eq, "fac_player_supporters_faction", slot_faction_state, 2),
        (str_store_string, s14, "str_as_you_no_longer_maintain_an_independent_kingdom_you_no_longer_maintain_a_court"),
    (try_end),
    (str_store_string, s12, 14),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_player_faction_deactive", 0,
"Your kingdom no longer holds any land.",
"none", 
[
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "fac_player_supporters_faction", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
        (try_end),
        (assign, "$g_player_minister", -1),
        (change_screen_return),
    ], "."),

]),

("notification_player_wedding_day", 4096,
"{s8} wishes to inform you that preparations for your wedding at {s10} have been complete, and that your presence is expected imminently .",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (str_store_troop_name, s8, "$g_notification_menu_var1"),
    (str_store_party_name, s10, "$g_notification_menu_var2"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_player_kingdom_holds_feast", 4096,
"{s11}",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (str_store_troop_name, s8, "$g_notification_menu_var1"),
    (store_troop_faction, ":var_0", "$g_notification_menu_var1"),
    (str_store_faction_name, s9, ":var_0"),
    (str_store_party_name, s10, "$g_notification_menu_var2"),
    (str_clear, s12),
    (try_begin),
        (check_quest_active, "qst_wed_betrothed"),
        (quest_get_slot, ":var_1", "qst_wed_betrothed", 6),
        (store_troop_faction, ":var_2", ":var_1"),
        (eq, ":var_2", "$players_kingdom"),
        (str_store_string, s12, "str_feast_wedding_opportunity"),
    (try_end),
    (str_store_string, s11, "str_s8_wishes_to_inform_you_that_the_lords_of_s9_will_be_gathering_for_a_feast_at_his_great_hall_in_s10_and_invites_you_to_be_part_of_this_august_assembly"),
    (try_begin),
        (eq, "$g_notification_menu_var1", 0),
        (str_store_string, s11, "str_the_great_lords_of_your_kingdom_plan_to_gather_at_your_hall_in_s10_for_a_feast"),
    (try_end),
    (str_store_string, s11, "@{!}{s11}{s12}"),
    (try_begin),
        (ge, "$cheat_mode", 1),
        (store_current_hours, ":var_3"),
        (faction_get_slot, ":var_4", "$players_kingdom", slot_faction_last_feast_concluded),
        (val_sub, ":var_3", ":var_4"),
        (assign, reg4, ":var_3"),
        (display_message, "@{!}DEBUG -- Hours since last feast started: {reg4}"),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_center_under_siege", 0,
"{s1} has been besieged by {s2} of the {s3}!",
"none", 
[
    (str_store_party_name, s1, "$g_notification_menu_var1"),
    (str_store_troop_name, s2, "$g_notification_menu_var2"),
    (store_troop_faction, ":var_0", "$g_notification_menu_var2"),
    (str_store_faction_name, s3, ":var_0"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 62),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_center_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_center_under_siege_special", 0,
"{s1} is under attack by {s2}!",
"none", 
[
    (str_store_party_name, s1, "$g_notification_menu_var1"),
    (str_store_party_name, s2, "$g_notification_menu_var2"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 62),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_center_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_village_raided", 0,
"Enemies have Laid Waste to a Fief^^{s1} has been raided by {s2} of the {s3}!",
"none", 
[
    (str_store_party_name, s1, "$g_notification_menu_var1"),
    (str_store_troop_name, s2, "$g_notification_menu_var2"),
    (store_troop_faction, ":var_0", "$g_notification_menu_var2"),
    (str_store_faction_name, s3, ":var_0"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 62),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_center_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_village_raid_started", 0,
"Your Village is under Attack!^^{s2} of the {s3} is laying waste to {s1}.",
"none", 
[
    (str_store_party_name, s1, "$g_notification_menu_var1"),
    (str_store_troop_name, s2, "$g_notification_menu_var2"),
    (store_troop_faction, ":var_0", "$g_notification_menu_var2"),
    (str_store_faction_name, s3, ":var_0"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 62),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_center_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_one_faction_left", 0,
"stub",
"none", 
[
    (jump_to_menu, "mnu_auto_return_to_map"),
    (music_set_situation, 0),
    (play_sound, "snd_end_game_victory_screen"),
    (try_begin),
        (faction_slot_eq, "$g_notification_menu_var1", slot_faction_leader, "trp_player"),
        (unlock_achievement, 44),
    (else_try),
        (unlock_achievement, 53),
    (try_end),
    (try_begin),
        (troop_get_type, ":var_0", "trp_player"),
        (ge, ":var_0", 1),
        (unlock_achievement, 78),
    (try_end),
    (start_presentation, "prsnt_victory_screen_simple"),
],
[
]),

("notification_order_founded", 0,
"stub",
"none", 
[
    (jump_to_menu, "mnu_auto_return_to_map"),
    (music_set_situation, 0),
    (play_sound, "snd_kinghorn"),
    (start_presentation, "prsnt_order_founded"),
],
[
]),

("notification_oath_renounced_faction_defeated", 0,
"Your Old Faction was Defeated^^You won the battle against the {s1}! This ends your struggle which started after you renounced your oath to them.",
"none", 
[
    (str_store_faction_name, s1, "$g_notification_menu_var1"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (try_begin),
        (is_between, "$g_notification_menu_var1", "fac_kingdom_1", "fac_kingdoms_end"),
        (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_for_menu", "$g_notification_menu_var1", pos0),
    (else_try),
        (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "$g_notification_menu_var1", pos0),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_center_lost", 0,
"An Estate was Lost^^You have lost {s1} to the {s2}.",
"none", 
[
    (str_store_party_name, s1, "$g_notification_menu_var1"),
    (str_store_faction_name, s2, "$g_notification_menu_var2"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 62),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_center_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_center_sacked", 0,
"An Estate was Sacked^^{s1} was sacked by the {s2}.",
"none", 
[
    (str_store_party_name, s1, "$g_notification_menu_var1"),
    (str_store_faction_name, s2, "$g_notification_menu_var2"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 62),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_center_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_troop_left_players_faction", 0,
"Betrayal!^^{s1} has left the {s2} and joined the {s3}.",
"none", 
[
    (str_store_troop_name, s1, "$g_notification_menu_var1"),
    (str_store_faction_name, s2, "$players_kingdom"),
    (str_store_faction_name, s3, "$g_notification_menu_var2"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 55),
    (position_set_y, pos0, 20),
    (position_set_z, pos0, 100),
    (set_game_menu_tableau_mesh, "tableau_troop_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_troop_joined_players_faction", 0,
"Good news!^^ {s1} has left the {s2} and joined the {s3}.",
"none", 
[
    (str_store_troop_name, s1, "$g_notification_menu_var1"),
    (str_store_faction_name, s2, "$g_notification_menu_var2"),
    (str_store_faction_name, s3, "$players_kingdom"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 55),
    (position_set_y, pos0, 20),
    (position_set_z, pos0, 100),
    (set_game_menu_tableau_mesh, "tableau_troop_note_mesh", "$g_notification_menu_var1", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_war_declared", 0,
"Declaration of War^^The {s1} declared war against the {s2}!",
"none", 
[
    (try_begin),
        (str_store_faction_name, s1, "$g_notification_menu_var1"),
        (str_store_faction_name, s2, "$g_notification_menu_var2"),
    (try_end),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (store_sub, ":var_0", "$g_notification_menu_var1", "fac_player_supporters_faction"),
    (store_sub, ":var_1", "$g_notification_menu_var2", "fac_player_supporters_faction"),
    (val_mul, ":var_0", 128),
    (val_add, ":var_0", ":var_1"),
    (set_game_menu_tableau_mesh, "tableau_2_factions_mesh", ":var_0", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_peace_declared", 0,
"Peace Agreement^^The {s1} and the {s2} have made peace!^{s57}",
"none", 
[
    (try_begin),
        (eq, 1, 0),
        (eq, "$g_include_diplo_explanation", "$g_notification_menu_var1"),
        (assign, "$g_include_diplo_explanation", 0),
    (else_try),
        (str_clear, s57),
    (try_end),
    (str_store_faction_name, s1, "$g_notification_menu_var1"),
    (str_store_faction_name, s2, "$g_notification_menu_var2"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (store_sub, ":var_0", "$g_notification_menu_var1", "fac_player_supporters_faction"),
    (store_sub, ":var_1", "$g_notification_menu_var2", "fac_player_supporters_faction"),
    (val_mul, ":var_0", 128),
    (val_add, ":var_0", ":var_1"),
    (set_game_menu_tableau_mesh, "tableau_2_factions_mesh", ":var_0", pos0),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_faction_defeated", 0,
"Faction Eliminated^^The {s1} is no more!",
"none", 
[
    (str_store_faction_name, s1, "$g_notification_menu_var1"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (try_begin),
        (is_between, "$g_notification_menu_var1", "fac_kingdom_1", "fac_kingdoms_end"),
        (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_for_menu", "$g_notification_menu_var1", pos0),
    (else_try),
        (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "$g_notification_menu_var1", pos0),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_begin),
            (is_between, "$supported_pretender", "trp_kingdom_1_pretender", "trp_knight_1_1_wife"),
            (troop_slot_eq, "$supported_pretender", slot_troop_original_faction, "$g_notification_menu_var1"),
            (try_for_range, ":var_0", "trp_npc_adonja", "trp_knight_1_1_wife"),
                (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
                (store_troop_faction, ":var_1", ":var_0"),
                (eq, ":var_1", "fac_player_supporters_faction"),
                (troop_set_faction, ":var_0", "$g_notification_menu_var1"),
                (call_script, "script_troop_set_title_according_to_faction", ":var_0", "$g_notification_menu_var1"),
                (try_begin),
                    (this_or_next|eq, "$g_notification_menu_var1", "$players_kingdom"),
                    (eq, "$g_notification_menu_var1", "fac_player_supporters_faction"),
                    (call_script, "script_check_concilio_calradi_achievement"),
                (try_end),
            (else_try),
                (troop_slot_eq, ":var_0", slot_troop_occupation, 2),
                (store_troop_faction, ":var_1", ":var_0"),
                (eq, ":var_1", "$g_notification_menu_var1"),
                (call_script, "script_troop_change_relation_with_troop", ":var_0", "trp_player", 5),
            (try_end),
            (try_for_parties, ":var_2"),
                (store_faction_of_party, ":var_1", ":var_2"),
                (eq, ":var_1", "fac_player_supporters_faction"),
                (party_set_faction, ":var_2", "$g_notification_menu_var1"),
            (try_end),
            (assign, "$players_kingdom", "$g_notification_menu_var1"),
            (try_begin),
                (troop_get_slot, ":var_3", "trp_player", slot_troop_spouse),
                (is_between, ":var_3", "trp_knight_1_1_wife", "trp_heroes_end"),
                (troop_set_faction, ":var_3", "$g_notification_menu_var1"),
            (try_end),
            (call_script, "script_add_notification_menu", "mnu_notification_rebels_switched_to_faction", "$g_notification_menu_var1", "$supported_pretender"),
            (faction_set_slot, "$g_notification_menu_var1", slot_faction_state, 0),
            (faction_set_slot, "fac_player_supporters_faction", slot_faction_state, 2),
            (faction_get_slot, ":var_4", "$g_notification_menu_var1", slot_faction_leader),
            (troop_set_slot, ":var_4", slot_troop_change_to_faction, "fac_commoners"),
            (faction_set_slot, "$g_notification_menu_var1", slot_faction_leader, "$supported_pretender"),
            (troop_set_faction, "$supported_pretender", "$g_notification_menu_var1"),
            (faction_get_slot, ":var_5", "$g_notification_menu_var1", slot_faction_marshall),
            (try_begin),
                (ge, ":var_5", 0),
                (troop_get_slot, ":var_6", ":var_5", slot_troop_leaded_party),
                (party_is_active, ":var_6"),
                (party_set_marshall, ":var_6", 0),
            (try_end),
            (faction_set_slot, "$g_notification_menu_var1", slot_faction_marshall, "trp_player"),
            (faction_set_slot, "$g_notification_menu_var1", slot_faction_ai_state, 0),
            (faction_set_slot, "$g_notification_menu_var1", slot_faction_ai_object, -1),
            (troop_set_slot, "$supported_pretender", slot_troop_occupation, 2),
            (troop_set_slot, "$supported_pretender", slot_troop_renown, 1000),
            (party_remove_members, "p_main_party", "$supported_pretender", 1),
            (call_script, "script_set_player_relation_with_faction", "$g_notification_menu_var1", 0),
            (try_for_range, ":var_7", "fac_player_supporters_faction", "fac_kingdoms_end"),
                (faction_slot_eq, ":var_7", slot_faction_state, 0),
                (neg|eq, ":var_7", "$g_notification_menu_var1"),
                (store_relation, ":var_8", ":var_7", "fac_player_supporters_faction"),
                (set_relation, ":var_7", "$g_notification_menu_var1", ":var_8"),
            (try_end),
            (assign, "$supported_pretender", 0),
            (assign, "$supported_pretender_old_faction", 0),
            (assign, "$g_recalculate_ais", 1),
            (call_script, "script_update_all_notes"),
        (try_end),
        (change_screen_return),
    ], "."),

]),

("notification_rebels_switched_to_faction", 0,
"Rebellion Success^^ Your rebellion is victorious! Your faction now has the sole claim to the title of the {s11}, with {s12} as the single ruler.",
"none", 
[
    (str_store_faction_name, s11, "$g_notification_menu_var1"),
    (str_store_troop_name, s12, "$g_notification_menu_var2"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (try_begin),
        (is_between, "$g_notification_menu_var1", "fac_kingdom_1", "fac_kingdoms_end"),
        (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_for_menu", "$g_notification_menu_var1", pos0),
    (else_try),
        (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_banner", "$g_notification_menu_var1", pos0),
    (try_end),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$talk_context", 15),
        (start_map_conversation, "$g_notification_menu_var2", -1),
        (change_screen_return),
    ], "."),

]),

("notification_player_should_consult", 0,
"Your minister send words that there are problems brewing in the realm which, if left untreated, could sap your authority. You should consult with him at your earliest convenience",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (setup_quest_text, "qst_consult_with_minister"),
        (str_store_troop_name, s11, "$g_player_minister"),
        (str_store_party_name, s12, "$g_player_court"),
        (str_store_string, s2, "str_consult_with_s11_at_your_court_in_s12"),
        (call_script, "script_start_quest", "qst_consult_with_minister", -1),
        (quest_set_slot, "qst_consult_with_minister", 23, 30),
        (quest_set_slot, "qst_consult_with_minister", 6, "$g_player_minister"),
        (change_screen_return),
    ], "."),

]),

("notification_player_feast_in_progress", 0,
"Feast in Preparation^^Your wife has started preparations for a feast in your hall in {s11}",
"none", 
[
    (str_store_party_name, s11, "$g_notification_menu_var1"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_lady_requests_visit", 0,
"An elderly woman approaches your party and passes one of your men a letter, sealed in plain wax. It is addressed to you. When you break the seal, you see it is from {s15}. It reads, 'I so enjoyed your last visit. {s14} I am currently in {s10}.{s12}'",
"none", 
[
    (assign, ":var_0", "$g_notification_menu_var1"),
    (assign, ":var_1", "$g_notification_menu_var2"),
    (str_store_troop_name, s15, ":var_0"),
    (str_store_party_name, s10, ":var_1"),
    (store_current_hours, ":var_2"),
    (troop_get_slot, ":var_3", ":var_0", slot_troop_last_talk_time),
    (val_sub, ":var_2", ":var_3"),
    (call_script, "script_get_kingdom_lady_social_determinants", ":var_0"),
    (assign, ":var_4", reg0),
    (str_store_troop_name, s16, ":var_4"),
    (call_script, "script_troop_get_family_relation_to_troop", ":var_4", ":var_0"),
    (str_clear, s14),
    (try_begin),
        (neg|ge, ":var_2", 336),
        (try_begin),
            (troop_slot_eq, ":var_0", slot_lord_reputation_type, 23),
            (str_store_string, s14, "str_as_brief_as_our_separation_has_been_the_longing_in_my_heart_to_see_you_has_made_it_seem_as_many_years"),
        (else_try),
            (str_store_string, s14, "str_although_it_has_only_been_a_short_time_since_your_departure_but_i_would_be_most_pleased_to_see_you_again"),
        (try_end),
    (else_try),
        (ge, ":var_2", 336),
        (try_begin),
            (troop_slot_eq, ":var_0", slot_lord_reputation_type, 24),
            (str_store_string, s14, "str_although_i_have_received_no_word_from_you_for_quite_some_time_i_am_sure_that_you_must_have_been_very_busy_and_that_your_failure_to_come_see_me_in_no_way_indicates_that_your_attentions_to_me_were_insincere_"),
        (else_try),
            (troop_slot_eq, ":var_0", slot_lord_reputation_type, 25),
            (str_store_string, s14, "str_i_trust_that_you_have_comported_yourself_in_a_manner_becoming_a_gentleman_during_our_long_separation_"),
        (else_try),
            (str_store_string, s14, "str_it_has_been_many_days_since_you_came_and_i_would_very_much_like_to_see_you_again"),
        (try_end),
    (try_end),
    (str_clear, s12),
    (str_clear, s18),
    (try_begin),
        (troop_slot_eq, ":var_4", slot_troop_love_interests_end, 0),
        (str_store_string, s12, "str__you_should_ask_my_s11_s16s_permission_but_i_have_no_reason_to_believe_that_he_will_prevent_you_from_coming_to_see_me"),
        (str_store_string, s18, "str__you_should_first_ask_her_s11_s16s_permission"),
    (else_try),
        (troop_slot_eq, ":var_4", slot_troop_love_interests_end, -1),
        (str_store_string, s12, "str__alas_as_we_know_my_s11_s16_will_not_permit_me_to_see_you_however_i_believe_that_i_can_arrange_away_for_you_to_enter_undetected"),
    (else_try),
        (troop_slot_eq, ":var_4", slot_troop_love_interests_end, 1),
        (str_store_string, s12, "str__as_my_s11_s16_has_already_granted_permission_for_you_to_see_me_i_shall_expect_your_imminent_arrival"),
    (try_end),
],
[
    ("continue", [],
    "Tell the woman to inform her mistress that you will come shortly",
    [
        (assign, ":var_0", "$g_notification_menu_var1"),
        (str_store_troop_name_link, s3, ":var_0"),
        (str_store_party_name_link, s4, "$g_notification_menu_var2"),
        (str_store_string, s2, "str_visit_s3_who_was_last_at_s4s18"),
        (call_script, "script_start_quest", "qst_visit_lady", ":var_0"),
        (quest_set_slot, "qst_visit_lady", 6, ":var_0"),
        (try_begin),
            (eq, "$cheat_mode", 1),
            (quest_get_slot, ":var_1", "qst_visit_lady", 6),
            (str_store_troop_name, s2, ":var_1"),
            (display_message, "str_giver_troop_=_s2"),
        (try_end),
        (quest_set_slot, "qst_visit_lady", 23, 30),
        (change_screen_return),
    ], "."),

    ("continue", [],
    "Tell the woman to inform her mistress that you are indisposed",
    [
        (troop_set_slot, "$g_notification_menu_var1", slot_troop_love_interest_3, 1),
        (change_screen_return),
    ], "."),

]),

("garden", 0,
"{s12}",
"none", 
[
    (call_script, "script_get_kingdom_lady_social_determinants", "$love_interest_in_town"),
    (assign, ":var_0", reg0),
    (str_store_troop_name, s11, "$love_interest_in_town"),
    (try_begin),
        (call_script, "script_npc_decision_checklist_male_guardian_assess_suitor", ":var_0", "trp_player"),
        (neg|ge, reg0, 0),
        (troop_set_slot, ":var_0", slot_troop_love_interests_end, -1),
    (try_end),
    (assign, "$nurse_assists_entry", 0),
    (try_begin),
        (troop_slot_eq, ":var_0", slot_troop_love_interests_end, 1),
        (str_store_string, s12, "str_the_guards_at_the_gate_have_been_ordered_to_allow_you_through_you_might_be_imagining_things_but_you_think_one_of_them_may_have_given_you_a_wink"),
    (else_try),
        (call_script, "script_troop_get_relation_with_troop", "trp_player", "$love_interest_in_town"),
        (gt, reg0, 0),
        (assign, ":var_1", 0),
        (try_begin),
            (check_quest_active, "qst_visit_lady"),
            (quest_slot_eq, "qst_visit_lady", 6, "$love_interest_in_town"),
            (assign, ":var_1", 1),
        (else_try),
            (check_quest_active, "qst_formal_marriage_proposal"),
            (quest_slot_eq, "qst_formal_marriage_proposal", 6, "$love_interest_in_town"),
            (this_or_next|check_quest_succeeded, "qst_formal_marriage_proposal"),
            (check_quest_failed, "qst_formal_marriage_proposal"),
            (assign, ":var_1", 1),
        (else_try),
            (check_quest_active, "qst_duel_courtship_rival"),
            (quest_slot_eq, "qst_duel_courtship_rival", 6, "$love_interest_in_town"),
            (this_or_next|check_quest_succeeded, "qst_duel_courtship_rival"),
            (check_quest_failed, "qst_duel_courtship_rival"),
            (assign, ":var_1", 1),
        (try_end),
        (try_begin),
            (store_current_hours, ":var_2"),
            (troop_get_slot, ":var_3", "$love_interest_in_town", slot_troop_last_talk_time),
            (val_sub, ":var_2", ":var_3"),
            (this_or_next|ge, ":var_2", 96),
            (eq, ":var_1", 1),
            (try_begin),
                (is_between, "$g_encountered_party", "p_town_1", "p_castle_1"),
                (str_store_string, s12, "str_the_guards_glare_at_you_and_you_know_better_than_to_ask_permission_to_enter_however_as_you_walk_back_towards_your_lodgings_an_elderly_lady_dressed_in_black_approaches_you_i_am_s11s_nurse_she_whispers_urgently_don_this_dress_and_throw_the_hood_over_your_face_i_will_smuggle_you_inside_the_castle_to_meet_her_in_the_guise_of_a_skullery_maid__the_guards_will_not_look_too_carefully_but_i_beg_you_for_all_of_our_sakes_be_discrete"),
                (assign, "$nurse_assists_entry", 1),
            (else_try),
                (str_store_string, s12, "str_the_guards_glare_at_you_and_you_know_better_than_to_ask_permission_to_enter_however_as_you_walk_back_towards_your_lodgings_an_elderly_lady_dressed_in_black_approaches_you_i_am_s11s_nurse_she_whispers_urgently_wait_for_a_while_by_the_spring_outside_the_walls_i_will_smuggle_her_ladyship_out_to_meet_you_dressed_in_the_guise_of_a_shepherdess_but_i_beg_you_for_all_of_our_sakes_be_discrete"),
                (assign, "$nurse_assists_entry", 2),
            (try_end),
        (else_try),
            (str_store_string, s12, "str_the_guards_glare_at_you_and_you_know_better_than_to_ask_permission_to_enter_however_as_you_walk_back_towards_your_lodgings_an_elderly_lady_dressed_in_black_approaches_you_i_am_s11s_nurse_she_whispers_urgently_her_ladyship_asks_me_to_say_that_yearns_to_see_you_but_that_you_should_bide_your_time_a_bit_her_ladyship_says_that_to_arrange_a_clandestine_meeting_so_soon_after_your_last_encounter_would_be_too_dangerous"),
        (try_end),
    (else_try),
        (str_store_string, s12, "str_the_guards_glare_at_you_and_you_know_better_than_to_ask_permission_to_enter"),
    (try_end),
],
[
    ("enter", 
    [
        (call_script, "script_get_kingdom_lady_social_determinants", "$love_interest_in_town"),
        (troop_slot_eq, reg0, slot_troop_love_interests_end, 1),
    ],
    "Enter",
    [
        (jump_to_menu, "mnu_town"),
        (call_script, "script_setup_meet_lady", "$love_interest_in_town", "$g_encountered_party"),
    ], "."),

    ("nurse", 
    [
        (eq, "$nurse_assists_entry", 1),
    ],
    "Go with the nurse",
    [
        (jump_to_menu, "mnu_town"),
        (call_script, "script_setup_meet_lady", "$love_interest_in_town", "$g_encountered_party"),
    ], "."),

    ("nurse", 
    [
        (eq, "$nurse_assists_entry", 2),
    ],
    "Wait by the spring",
    [
        (jump_to_menu, "mnu_town"),
        (call_script, "script_setup_meet_lady", "$love_interest_in_town", "$g_encountered_party"),
    ], "."),

    ("leave", [],
    "Leave",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("kill_local_merchant_begin", 0,
"You spot your victim and follow him, observing as he turns a corner into a dark alley. This will surely be your best opportunity to attack him.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (set_jump_mission, "mt_back_alley_kill_local_merchant"),
        (party_get_slot, ":var_0", "$qst_kill_local_merchant_center", slot_town_alley),
        (modify_visitors_at_site, ":var_0"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 1, "trp_local_merchant"),
        (jump_to_menu, "mnu_town"),
        (jump_to_scene, ":var_0"),
        (change_screen_mission),
    ], "."),

]),

("debug_alert_from_s65", 0,
"DEBUG ALERT: {s65}",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$debug_message_in_queue", 0),
        (change_screen_return),
    ], "."),

]),

("auto_return_to_map", 0,
"stub",
"none", 
[
    (change_screen_map),
],
[
]),

("bandit_lair", 0,
"{s3}",
"none", 
[
    (try_begin),
        (eq, "$loot_screen_shown", 1),
        (try_for_range, ":var_0", "pt_steppe_bandits", "pt_deserters"),
            (party_template_slot_eq, ":var_0", slot_party_template_lair_party, "$g_encountered_party"),
            (party_template_set_slot, ":var_0", slot_party_template_lair_party, 0),
        (try_end),
        (try_begin),
            (ge, "$g_encountered_party", 0),
            (party_is_active, "$g_encountered_party"),
            (party_get_template_id, ":var_1", "$g_encountered_party"),
            (neg|eq, ":var_1", "pt_looter_lair"),
            (remove_party, "$g_encountered_party"),
        (try_end),
        (assign, "$g_leave_encounter", 0),
        (change_screen_return),
    (else_try),
        (party_stack_get_troop_id, ":var_2", "$g_encountered_party", 0),
        (str_store_troop_name_plural, s4, ":var_2"),
        (str_store_string, s5, "str_bandit_approach_defile"),
        (try_begin),
            (eq, ":var_2", "trp_mountain_bandit"),
            (str_store_string, s5, "str_bandit_approach_cliffs"),
        (else_try),
            (eq, ":var_2", "trp_forest_bandit"),
            (str_store_string, s5, "str_bandit_approach_swamp"),
        (else_try),
            (eq, ":var_2", "trp_snake_follower"),
            (str_store_string, s5, "str_bandit_approach_swamp"),
        (else_try),
            (eq, ":var_2", "trp_steppe_bandit"),
            (str_store_string, s5, "str_bandit_approach_thickets"),
        (else_try),
            (eq, ":var_2", "trp_sea_raider"),
            (str_store_string, s5, "str_bandit_approach_cove"),
        (try_end),
        (try_begin),
            (party_get_template_id, ":var_1", "$g_encountered_party"),
            (eq, ":var_1", "pt_looter_lair"),
            (check_quest_active, "qst_save_relative_of_merchant"),
            (store_faction_of_party, ":var_3", "$g_starting_town"),
            (store_sub, ":var_4", ":var_3", "fac_kingdom_1"),
            (store_add, ":var_5", "str_bandits_sarleon", ":var_4"),
            (str_store_string, s4, ":var_5"),
        (try_end),
        (try_begin),
            (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 0),
            (str_store_string, s3, "str_bandit_hideout_preattack"),
        (else_try),
            (party_get_template_id, ":var_1", "$g_encountered_party"),
            (eq, ":var_1", "pt_looter_lair"),
            (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 1),
            (str_store_string, s3, "str_lost_startup_hideout_attack"),
        (else_try),
            (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 1),
            (str_store_string, s3, "str_bandit_hideout_failure"),
        (else_try),
            (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 2),
            (str_store_string, s3, "str_bandit_hideout_success"),
        (try_end),
    (try_end),
],
[
    ("continue_1", 
    [
        (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 0),
    ],
    "Attack the hideout...",
    [
        (party_set_slot, "$g_encountered_party", slot_party_ai_substate, 1),
        (party_get_template_id, ":var_0", "$g_encountered_party"),
        (assign, "$g_enemy_party", "$g_encountered_party"),
        (try_begin),
            (eq, ":var_0", "pt_sea_raider_lair"),
            (assign, ":var_1", "trp_sea_raider"),
            (assign, ":var_2", "scn_lair_sea_raiders"),
        (else_try),
            (eq, ":var_0", "pt_forest_bandit_lair"),
            (assign, ":var_1", "trp_forest_bandit"),
            (assign, ":var_2", "scn_lair_forest_bandits"),
        (else_try),
            (eq, ":var_0", "pt_mountain_bandit_lair"),
            (assign, ":var_1", "trp_mountain_bandit"),
            (assign, ":var_2", "scn_lair_taiga_bandits"),
        (else_try),
            (eq, ":var_0", "pt_snake_bandit_lair"),
            (assign, ":var_1", "trp_snake_armsman"),
            (assign, ":var_2", "scn_lair_mountain_bandits"),
        (else_try),
            (eq, ":var_0", "pt_steppe_bandit_lair"),
            (assign, ":var_1", "trp_steppe_bandit"),
            (assign, ":var_2", "scn_lair_steppe_bandits"),
        (else_try),
            (eq, ":var_0", "pt_looter_lair"),
            (assign, ":var_1", "trp_looter"),
            (store_faction_of_party, ":var_3", "$g_starting_town"),
            (try_begin),
                (eq, ":var_3", "fac_kingdom_1"),
                (assign, ":var_2", "scn_lair_forest_bandits"),
            (else_try),
                (eq, ":var_3", "fac_kingdom_2"),
                (assign, ":var_2", "scn_lair_taiga_bandits"),
            (else_try),
                (eq, ":var_3", "fac_kingdom_3"),
                (assign, ":var_2", "scn_lair_steppe_bandits"),
            (else_try),
                (eq, ":var_3", "fac_kingdom_4"),
                (assign, ":var_2", "scn_lair_sea_raiders"),
            (else_try),
                (eq, ":var_3", "fac_kingdom_5"),
                (assign, ":var_2", "scn_lair_mountain_bandits"),
            (try_end),
        (else_try),
            (eq, ":var_0", "pt_treasure_lair"),
            (assign, ":var_1", "trp_rb_guildsman"),
            (assign, ":var_2", "scn_lair_treasure"),
        (try_end),
        (modify_visitors_at_site, ":var_2"),
        (reset_visitors),
        (store_character_level, ":var_4", "trp_player"),
        (store_add, ":var_5", 5, ":var_4"),
        (val_div, ":var_5", 3),
        (try_for_range, ":var_6", 0, ":var_5"),
            (store_random_in_range, ":var_7", 2, 11),
            (set_visitor, ":var_7", ":var_1", 1),
        (try_end),
        (party_clear, "p_temp_casualties"),
        (set_party_battle_mode),
        (set_battle_advantage, 0),
        (assign, "$g_battle_result", 0),
        (set_jump_mission, "mt_bandit_lair"),
        (jump_to_scene, ":var_2"),
        (change_screen_mission),
    ], "."),

    ("leave_no_attack", 
    [
        (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 0),
    ],
    "Leave...",
    [
        (change_screen_return),
    ], "."),

    ("leave_victory", 
    [
        (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 2),
    ],
    "Continue...",
    [
        (try_for_range, ":var_0", "pt_steppe_bandits", "pt_deserters"),
            (party_template_slot_eq, ":var_0", slot_party_template_lair_party, "$g_encountered_party"),
            (party_template_set_slot, ":var_0", slot_party_template_lair_party, 0),
        (try_end),
        (party_get_template_id, ":var_1", "$g_encountered_party"),
        (try_begin),
            (neg|eq, ":var_1", "pt_looter_lair"),
            (check_quest_active, "qst_destroy_bandit_lair"),
            (quest_slot_eq, "qst_destroy_bandit_lair", 8, "$g_encountered_party"),
            (call_script, "script_succeed_quest", "qst_destroy_bandit_lair"),
        (try_end),
        (assign, "$g_leave_encounter", 0),
        (change_screen_return),
        (try_begin),
            (eq, "$loot_screen_shown", 0),
            (assign, "$loot_screen_shown", 1),
            (try_begin),
                (gt, "$g_ally_party", 0),
                (call_script, "script_party_add_party", "$g_ally_party", "p_temp_party"),
            (else_try),
                (party_get_num_attached_parties, ":var_2", "p_main_party"),
                (gt, ":var_2", 0),
                (party_get_attached_party_with_rank, ":var_3", "p_main_party", 0),
                (call_script, "script_party_add_party", ":var_3", "p_temp_party"),
            (try_end),
            (troop_clear_inventory, "trp_temp_troop"),
            (party_get_num_companion_stacks, ":var_4", "p_temp_casualties"),
            (try_for_range, ":var_5", 0, ":var_4"),
                (party_stack_get_troop_id, ":var_6", "p_temp_casualties", ":var_5"),
                (try_begin),
                    (party_stack_get_size, ":var_7", "p_temp_casualties", ":var_5"),
                    (party_stack_get_troop_id, ":var_6", "p_temp_casualties", ":var_5"),
                    (gt, ":var_7", 0),
                    (party_add_members, "p_total_enemy_casualties", ":var_6", ":var_7"),
                    (party_stack_get_num_wounded, ":var_8", "p_temp_casualties", ":var_5"),
                    (gt, ":var_8", 0),
                    (party_wound_members, "p_total_enemy_casualties", ":var_6", ":var_8"),
                (try_end),
            (try_end),
            (call_script, "script_party_calculate_loot", "p_total_enemy_casualties"),
            (gt, reg0, 0),
            (troop_sort_inventory, "trp_temp_troop"),
            (change_screen_loot, "trp_temp_troop"),
        (try_end),
        (try_begin),
            (ge, "$g_encountered_party", 0),
            (party_is_active, "$g_encountered_party"),
            (party_get_template_id, ":var_1", "$g_encountered_party"),
            (eq, ":var_1", "pt_looter_lair"),
            (remove_party, "$g_encountered_party"),
        (try_end),
    ], "."),

    ("leave_defeat", 
    [
        (party_slot_eq, "$g_encountered_party", slot_party_ai_substate, 1),
    ],
    "Continue...",
    [
        (try_for_range, ":var_0", "pt_steppe_bandits", "pt_deserters"),
            (party_template_slot_eq, ":var_0", slot_party_template_lair_party, "$g_encountered_party"),
            (party_template_set_slot, ":var_0", slot_party_template_lair_party, 0),
        (try_end),
        (try_begin),
            (party_get_template_id, ":var_1", "$g_encountered_party"),
            (neg|eq, ":var_1", "pt_looter_lair"),
            (check_quest_active, "qst_destroy_bandit_lair"),
            (quest_slot_eq, "qst_destroy_bandit_lair", 8, "$g_encountered_party"),
            (call_script, "script_fail_quest", "qst_destroy_bandit_lair"),
        (try_end),
        (try_begin),
            (ge, "$g_encountered_party", 0),
            (party_is_active, "$g_encountered_party"),
            (party_get_template_id, ":var_1", "$g_encountered_party"),
            (neg|eq, ":var_1", "pt_looter_lair"),
            (remove_party, "$g_encountered_party"),
        (try_end),
        (assign, "$g_leave_encounter", 0),
        (try_begin),
            (party_is_active, "$g_encountered_party"),
            (party_set_slot, "$g_encountered_party", slot_party_ai_substate, 0),
        (try_end),
        (change_screen_return),
    ], "."),

]),

("notification_player_faction_political_issue_resolved", 0,
"After consulting with the peers of the realm, {s10} has decided to confer {s11} on {s12}.",
"none", 
[
    (assign, ":var_0", "$g_notification_menu_var1"),
    (assign, ":var_1", "$g_notification_menu_var2"),
    (faction_get_slot, ":var_2", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s10, ":var_2"),
    (try_begin),
        (eq, ":var_0", 1),
        (str_store_string, s11, "str_the_marshalship"),
    (else_try),
        (str_store_party_name, s11, ":var_0"),
    (try_end),
    (str_store_troop_name, s12, ":var_1"),
],
[
    ("continue", [],
    "Continue...",
    [
        (change_screen_return),
    ], "."),

]),

("notification_player_faction_political_issue_resolved_for_player", 0,
"After consulting with the peers of the realm, {s10} has decided to confer {s11} on you. You may decline the honor, but it will probably mean that you will not receive other awards for a little while.{s12}",
"none", 
[
    (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s10, ":var_0"),
    (faction_get_slot, ":var_1", "$players_kingdom", slot_faction_political_issue),
    (try_begin),
        (eq, ":var_1", 1),
        (str_store_string, s11, "str_the_marshalship"),
        (str_store_string, s12, "@^^Note that so long as you remain marshal, the lords of the realm will be expecting you to lead them on campaign. So, if you are awaiting a feast, either for a wedding or for other purposes, you may wish to resign the marshalship by speaking to your liege."),
    (else_try),
        (str_clear, s12),
        (str_store_party_name, s11, ":var_1"),
    (try_end),
],
[
    ("accept", [],
    "Accept the honor",
    [
        (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_political_issue),
        (try_begin),
            (eq, ":var_0", 1),
            (call_script, "script_check_and_finish_active_army_quests_for_faction", "$players_kingdom"),
            (call_script, "script_appoint_faction_marshall", "$players_kingdom", "trp_player"),
            (unlock_achievement, 41),
        (else_try),
            (call_script, "script_give_center_to_lord", ":var_0", "trp_player", 0),
        (try_end),
        (faction_set_slot, "$players_kingdom", slot_faction_political_issue, 0),
        (try_for_range, ":var_1", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (store_troop_faction, ":var_2", ":var_1"),
            (eq, ":var_2", "$players_kingdom"),
            (troop_set_slot, ":var_1", slot_troop_stance_on_faction_issue, -1),
        (try_end),
        (change_screen_return),
    ], "."),

    ("decline", [],
    "Decline the honor",
    [
        (faction_get_slot, ":var_0", "$players_kingdom", slot_faction_political_issue),
        (try_begin),
            (is_between, ":var_0", "p_town_1", "p_salt_mine"),
            (assign, "$g_dont_give_fief_to_player_days", 30),
        (else_try),
            (assign, "$g_dont_give_marshalship_to_player_days", 30),
        (try_end),
        (try_for_range, ":var_1", "trp_npc_adonja", "trp_knight_1_1_wife"),
            (store_troop_faction, ":var_2", ":var_1"),
            (eq, ":var_2", "$players_kingdom"),
            (troop_set_slot, ":var_1", slot_troop_stance_on_faction_issue, -1),
        (try_end),
        (change_screen_return),
    ], "."),

]),

("start_phase_2_5", 512,
"{!}{s16}",
"none", 
[
    (str_store_party_name, s1, "$g_starting_town"),
    (str_store_string, s16, "$g_journey_string"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_start_phase_3"),
    ], "."),

]),

("start_phase_3", 512,
"{s16}^^Exhausted by the time you find the inn in {s1}, and fall asleep quickly. Awake before dawn and eager to explore your surroundings, you venture out onto the streets, which are still deserted in the early morn. Suddenly, the rasp of a blade sliding from its scabbard makes the hairs of your neck stand on end. You are instantly on the alert for trouble ...",
"none", 
[
    (assign, ":var_0", 1),
    (try_begin),
        (eq, "$current_startup_quest_phase", 1),
        (try_begin),
            (eq, "$g_killed_first_bandit", 1),
            (str_store_string, s11, "str_killed_bandit_at_alley_fight"),
        (else_try),
            (str_store_string, s11, "str_wounded_by_bandit_at_alley_fight"),
        (try_end),
        (jump_to_menu, "mnu_start_phase_4"),
        (assign, ":var_0", 0),
    (else_try),
        (eq, "$current_startup_quest_phase", 3),
        (try_begin),
            (eq, "$g_killed_first_bandit", 1),
            (str_store_string, s11, "str_killed_bandit_at_alley_fight"),
        (else_try),
            (str_store_string, s11, "str_wounded_by_bandit_at_alley_fight"),
        (try_end),
        (jump_to_menu, "mnu_start_phase_4"),
        (assign, ":var_0", 0),
    (try_end),
    (str_store_party_name, s1, "$g_starting_town"),
    (str_clear, s16),
    (eq, ":var_0", 1),
],
[
    ("continue", [],
    "Continue...",
    [
        (assign, "$g_starting_town", "$current_town"),
        (call_script, "script_player_arrived"),
        (party_set_morale, "p_main_party", 100),
        (set_encountered_party, "$current_town"),
        (call_script, "script_prepare_alley_to_fight"),
    ], "."),

]),

("start_phase_4", 512,
"{s11}",
"none", 
[
    (assign, ":var_0", 1),
    (try_begin),
        (eq, "$current_startup_quest_phase", 2),
        (change_screen_return),
        (assign, ":var_0", 0),
    (else_try),
        (eq, "$current_startup_quest_phase", 3),
        (str_store_string, s11, "str_merchant_and_you_call_some_townsmen_and_guards_to_get_ready_and_you_get_out_from_tavern"),
    (else_try),
        (eq, "$current_startup_quest_phase", 4),
        (try_begin),
            (eq, "$g_killed_first_bandit", 1),
            (str_store_string, s11, "str_town_fight_ended_you_and_citizens_cleaned_town_from_bandits"),
        (else_try),
            (str_store_string, s11, "str_town_fight_ended_you_and_citizens_cleaned_town_from_bandits_you_wounded"),
        (try_end),
    (try_end),
    (eq, ":var_0", 1),
],
[
    ("continue", 
    [
        (this_or_next|eq, "$current_startup_quest_phase", 1),
        (eq, "$current_startup_quest_phase", 4),
    ],
    "Continue...",
    [
        (assign, "$town_entered", 1),
        (try_begin),
            (eq, "$current_town", "p_town_1"),
            (assign, ":var_0", "trp_fierdsvain_merchant"),
            (assign, ":var_1", "scn_town_1_room"),
        (else_try),
            (eq, "$current_town", "p_town_5"),
            (assign, ":var_0", "trp_empire_merchant"),
            (assign, ":var_1", "scn_town_5_room"),
        (else_try),
            (eq, "$current_town", "p_town_6"),
            (assign, ":var_0", "trp_sarleon_merchant"),
            (assign, ":var_1", "scn_town_6_room"),
        (else_try),
            (eq, "$current_town", "p_town_8"),
            (assign, ":var_0", "trp_ravenstern_merchant"),
            (assign, ":var_1", "scn_town_8_room"),
        (else_try),
            (eq, "$current_town", "p_town_10"),
            (assign, ":var_0", "trp_dshar_merchant"),
            (assign, ":var_1", "scn_town_10_room"),
        (try_end),
        (modify_visitors_at_site, ":var_1"),
        (reset_visitors),
        (set_visitor, 0, "trp_player"),
        (set_visitor, 9, ":var_0"),
        (assign, "$talk_context", 21),
        (assign, "$dialog_with_merchant_ended", 0),
        (set_jump_mission, "mt_meeting_merchant"),
        (jump_to_scene, ":var_1"),
        (change_screen_mission),
    ], "."),

    ("continue", 
    [
        (eq, "$current_startup_quest_phase", 3),
    ],
    "Continue...",
    [
        (call_script, "script_prepare_town_to_fight"),
    ], "."),

]),

("lost_tavern_duel", 512,
"{s11}",
"none", 
[
    (try_begin),
        (agent_get_troop_id, ":var_0", "$g_main_attacker_agent"),
        (eq, ":var_0", "trp_belligerent_drunk"),
        (str_store_string, s11, "str_lost_tavern_duel_ordinary"),
    (else_try),
        (agent_get_troop_id, ":var_0", "$g_main_attacker_agent"),
        (eq, ":var_0", "trp_hired_assassin"),
        (str_store_string, s11, "str_lost_tavern_duel_assassin"),
    (try_end),
    (troop_set_slot, "trp_hired_assassin", slot_troop_cur_center, -1),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("grandmaster_ambush_lost", 512,
"The sudden Snake Cult attack caught you by surprise and you were knocked out under their furious blows. You woke up dazed and unable to comprehend what has just happened and why.",
"none", 
[
    (call_script, "script_change_troop_renown", "trp_player", -10),
    (troop_get_slot, ":var_0", "trp_player", 162),
    (store_troop_faction, ":var_1", ":var_0"),
    (str_store_faction_name, s9, ":var_1"),
    (setup_quest_text, "qst_order_grandmaster"),
    (str_store_string, s2, "@Speak to the Order representative of the {s9}."),
    (call_script, "script_start_quest", "qst_order_grandmaster", ":var_0"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("grandmaster_ambush_won", 512,
"The sudden Snake Cult attack was furious, yet you and your fellow Order Knights dispatched the intruders quickly. There's no obvious explanation why this happened and you must look for answers now.",
"none", 
[
    (call_script, "script_change_troop_renown", "trp_player", 10),
    (troop_get_slot, ":var_0", "trp_player", 162),
    (store_troop_faction, ":var_1", ":var_0"),
    (str_store_faction_name, s9, ":var_1"),
    (setup_quest_text, "qst_order_grandmaster"),
    (str_store_string, s2, "@Speak to the Order representative of the {s9}."),
    (call_script, "script_start_quest", "qst_order_grandmaster", ":var_0"),
],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("establish_court", 512,
"To establish {s4} as your court will require a small refurbishment. In particular, you will need a set of tools and a bolt of velvet. it may also take a short while for some of your followers to relocate here. Do you wish to proceed?",
"none", 
[
    (str_store_party_name, s4, "$g_encountered_party"),
],
[
    ("establish", 
    [
        (player_has_item, "itm_tools"),
        (player_has_item, "itm_velvet"),
    ],
    "Establish {s4} as your court",
    [
        (assign, "$g_player_court", "$current_town"),
        (troop_remove_item, "trp_player", "itm_tools"),
        (troop_remove_item, "trp_player", "itm_velvet"),
        (jump_to_menu, "mnu_town"),
    ], "."),

    ("continue", [],
    "Hold off...",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("notification_relieved_as_marshal", 512,
"{s4} wishes to inform you that your services as marshal are no longer required. In honor of valiant efforts on behalf of the realm over the last {reg4} days, however, {reg8?she:he} offers you a purse of {reg5} denars.",
"none", 
[
    (assign, reg4, "$g_player_days_as_marshal"),
    (store_div, ":var_0", "$g_player_days_as_marshal", 4),
    (val_min, ":var_0", 20),
    (store_mul, ":var_1", "$g_player_days_as_marshal", 50),
    (val_max, ":var_1", 200),
    (val_min, ":var_1", 4000),
    (troop_add_gold, "trp_player", ":var_1"),
    (call_script, "script_change_troop_renown", "trp_player", ":var_0"),
    (assign, "$g_player_days_as_marshal", 0),
    (assign, "$g_dont_give_marshalship_to_player_days", 15),
    (assign, reg5, ":var_1"),
    (faction_get_slot, ":var_2", "$players_kingdom", slot_faction_leader),
    (str_store_troop_name, s4, ":var_2"),
    (troop_get_type, reg8, ":var_2"),
],
[
    ("continue", [],
    "Continue",
    [
        (change_screen_return),
    ], "."),

]),

("manage_loot_pool", 0,
"{s10}^{s30}",
"none", 
[
    (assign, "$pool_troop", "trp_temp_troop"),
    (assign, reg20, 0),
    (troop_get_inventory_capacity, ":var_0", "$pool_troop"),
    (try_for_range, ":var_1", 0, ":var_0"),
        (troop_get_inventory_slot, ":var_2", "$pool_troop", ":var_1"),
        (ge, ":var_2", 0),
        (val_add, reg20, 1),
    (try_end),
    (try_begin),
        (eq, reg20, 0),
        (str_store_string, s10, "str_item_pool_no_items"),
        (str_store_string, s20, "str_item_pool_leave"),
    (else_try),
        (eq, reg20, 1),
        (str_store_string, s10, "str_item_pool_one_item"),
        (str_store_string, s20, "str_item_pool_abandon"),
    (else_try),
        (str_store_string, s10, "str_item_pool_many_items"),
        (str_store_string, s20, "str_item_pool_abandon"),
    (try_end),
    (try_begin),
        (troop_get_slot, ":var_1", "trp_loot_pool", 188),
        (troop_get_slot, ":var_2", "trp_loot_pool", 189),
        (gt, ":var_1", 0),
        (ge, ":var_1", ":var_2"),
        (str_store_string, s20, "str_select_item_and_leave"),
    (try_end),
    (assign, reg10, 0),
    (assign, reg11, 0),
    (assign, reg12, 0),
    (assign, reg13, 0),
    (assign, reg14, 0),
    (party_get_num_companion_stacks, ":var_3", "p_main_party"),
    (try_for_range, ":var_4", 1, ":var_3"),
        (party_stack_get_troop_id, ":var_5", "p_main_party", ":var_4"),
        (is_between, ":var_5", "trp_npc_adonja", "trp_kingdom_1_lord"),
        (val_add, reg10, 1),
        (try_begin),
            (store_add, reg2, "$inventory_menu_offset", 1),
            (eq, reg10, reg2),
            (assign, reg11, ":var_5"),
            (str_store_troop_name, s11, ":var_5"),
        (else_try),
            (store_add, reg2, "$inventory_menu_offset", 2),
            (eq, reg10, reg2),
            (assign, reg12, ":var_5"),
            (str_store_troop_name, s12, ":var_5"),
        (else_try),
            (store_add, reg2, "$inventory_menu_offset", 3),
            (eq, reg10, reg2),
            (assign, reg13, ":var_5"),
            (str_store_troop_name, s13, ":var_5"),
        (else_try),
            (store_add, reg2, "$inventory_menu_offset", 4),
            (eq, reg10, reg2),
            (assign, reg14, ":var_5"),
            (str_store_troop_name, s14, ":var_5"),
        (try_end),
    (try_end),
],
[
    ("auto_no_companions", 
    [
        (eq, reg10, 0),
        (disable_menu_option),
    ],
    "I have no companions to give loot to, yet",
    [
    ], "."),

    ("auto_loot", 
    [
        (gt, reg10, 0),
        (eq, "$inventory_menu_offset", 0),
        (store_free_inventory_capacity, ":var_0", "$pool_troop"),
        (ge, ":var_0", 10),
        (try_begin),
            (eq, reg20, 0),
            (disable_menu_option),
        (try_end),
    ],
    "Let your heroes select gear from the item pool.",
    [
        (call_script, "script_auto_loot_all"),
        (jump_to_menu, "mnu_manage_loot_pool"),
    ], "."),

    ("set_limit", 
    [
        (troop_get_slot, ":var_0", "trp_loot_pool", 188),
        (troop_get_slot, ":var_1", "trp_loot_pool", 189),
        (gt, ":var_0", 0),
        (ge, ":var_0", ":var_1"),
    ],
    "set limit",
    [
        (assign, "$temp", 100),
        (start_presentation, "prsnt_numeric_input"),
    ], "."),

    ("auto_loot_no", 
    [
        (gt, reg10, 0),
        (gt, reg20, 0),
        (eq, "$inventory_menu_offset", 0),
        (store_free_inventory_capacity, ":var_0", "$pool_troop"),
        (neg|ge, ":var_0", 10),
        (disable_menu_option),
    ],
    "Insufficient item pool space for auto-upgrade.",
    [
    ], "."),

    ("prev", 
    [
        (gt, reg10, 0),
        (neg|eq, "$inventory_menu_offset", 0),
    ],
    "[Previous page]",
    [
        (val_sub, "$inventory_menu_offset", 4),
        (jump_to_menu, "mnu_manage_loot_pool"),
    ], "."),

    ("next", 
    [
        (gt, reg10, 0),
        (try_begin),
            (neg|gt, reg10, 4),
            (disable_menu_option),
        (else_try),
            (store_sub, reg2, reg10, 4),
            (ge, "$inventory_menu_offset", reg2),
            (disable_menu_option),
        (try_end),
    ],
    "[Next page]",
    [
        (val_add, "$inventory_menu_offset", 4),
        (jump_to_menu, "mnu_manage_loot_pool"),
    ], "."),

    ("loot", [],
    "Access the item pool.",
    [
        (change_screen_loot, "$pool_troop"),
    ], "."),

    ("companion1", 
    [
        (gt, reg11, 0),
    ],
    "Talk to {s11}",
    [
        (call_script, "script_loot_menu_talk", reg11),
    ], "."),

    ("companion2", 
    [
        (gt, reg12, 0),
    ],
    "Talk to {s12}",
    [
        (call_script, "script_loot_menu_talk", reg12),
    ], "."),

    ("companion3", 
    [
        (gt, reg13, 0),
    ],
    "Talk to {s13}",
    [
        (call_script, "script_loot_menu_talk", reg13),
    ], "."),

    ("companion4", 
    [
        (gt, reg14, 0),
    ],
    "Talk to {s14}",
    [
        (call_script, "script_loot_menu_talk", reg14),
    ], "."),

    ("loot_leave", [],
    "{s20}",
    [
        (try_begin),
            (troop_get_slot, ":var_0", "trp_loot_pool", 188),
            (troop_get_slot, ":var_1", "trp_loot_pool", 189),
            (gt, ":var_0", 0),
            (ge, ":var_0", ":var_1"),
            (call_script, "script_npc_select_items", "$pool_troop", "trp_loot_pool"),
            (assign, reg1, 0),
            (try_begin),
                (gt, reg0, 1),
                (assign, reg1, 1),
                (display_message, "@There are {reg0} {reg1?items:item} selected by your companions."),
            (else_try),
                (gt, reg0, 0),
                (display_message, "@There are {reg0} {reg1?items:item} selected by your companions."),
            (else_try),
                (display_message, "@Nothing can be selected."),
            (try_end),
        (try_end),
        (assign, "$g_camp_talk", 0),
        (jump_to_menu, "$return_menu"),
    ], "."),

]),

("achievement_notify", 0,
"stub",
"none", 
[
    (jump_to_menu, "mnu_auto_return_to_map"),
    (call_script, "script_gender_to_reg63"),
    (str_store_string, s11, "$g_notification_menu_var1"),
    (assign, reg11, "$g_notification_menu_var2"),
    (try_begin),
        (eq, reg11, 24),
        (call_script, "script_change_player_honor", -30),
        (call_script, "script_objectionable_action", 1, "str_cheat_in_battle"),
    (else_try),
        (assign, ":var_0", 0),
        (store_and, ":var_0", "$g_achieve_bitfield", 67108864),
        (neg|eq, ":var_0", 0),
    (else_try),
        (eq, reg11, 0),
        (call_script, "script_change_troop_renown", "trp_player", 20),
    (else_try),
        (eq, reg11, 1),
        (troop_raise_skill, "trp_player", skl_trainer, 1),
        (display_message, "@Your Trainer skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 2),
        (troop_raise_skill, "trp_player", skl_trainer, 2),
        (display_message, "@Your Trainer skill has increased by 2.", 0x50FF50),
    (else_try),
        (eq, reg11, 3),
        (troop_raise_skill, "trp_player", skl_tactics, 1),
        (display_message, "@Your Tactics skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 4),
        (troop_raise_skill, "trp_player", skl_tactics, 2),
        (display_message, "@Your Tactics skill has increased by 2.", 0x50FF50),
    (else_try),
        (eq, reg11, 5),
        (troop_raise_attribute, "trp_player", ca_intelligence, 1),
        (display_message, "@Your Intelligence has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 6),
        (troop_raise_attribute, "trp_player", ca_intelligence, 2),
        (display_message, "@Your Intelligence has increased by 2.", 0x50FF50),
    (else_try),
        (eq, reg11, 7),
        (troop_raise_attribute, "trp_player", ca_agility, 1),
        (display_message, "@Your Agility has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 8),
        (troop_raise_skill, "trp_player", skl_ironflesh, 1),
        (display_message, "@Your Ironflesh skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 9),
        (troop_raise_skill, "trp_player", skl_riding, 1),
        (display_message, "@Your Riding skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 10),
        (troop_raise_attribute, "trp_player", ca_strength, 1),
        (display_message, "@Your Strength has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 11),
        (call_script, "script_change_troop_renown", "trp_player", 100),
    (else_try),
        (eq, reg11, 12),
        (troop_raise_skill, "trp_player", skl_weapon_master, 1),
        (display_message, "@Your Weapon Master skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 13),
        (troop_raise_attribute, "trp_player", ca_charisma, 1),
        (display_message, "@Your Charisma has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 14),
        (troop_raise_attribute, "trp_player", ca_charisma, 2),
        (display_message, "@Your Charisma has increased by 2.", 0x50FF50),
    (else_try),
        (eq, reg11, 15),
        (troop_raise_attribute, "trp_player", ca_charisma, 1),
        (display_message, "@Your Charisma has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 16),
        (troop_raise_skill, "trp_player", skl_leadership, 1),
        (display_message, "@Your Leadership skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 17),
        (troop_raise_skill, "trp_player", skl_persuasion, 1),
        (display_message, "@Your Persuasion skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 18),
        (troop_raise_skill, "trp_player", skl_engineer, 1),
        (display_message, "@Your Engineer skill has increased by 1.", 0x50FF50),
    (else_try),
        (eq, reg11, 19),
        (call_script, "script_change_troop_renown", "trp_player", 20),
    (else_try),
        (eq, reg11, 20),
        (call_script, "script_change_troop_renown", "trp_player", -10),
    (else_try),
        (eq, reg11, 21),
        (troop_raise_skill, "trp_player", skl_tactics, -1),
        (display_message, "@Your Tactics skill has decreased by 1.", 0xFF5050),
    (else_try),
        (eq, reg11, 22),
        (troop_raise_attribute, "trp_player", ca_charisma, -1),
        (display_message, "@Your Charisma has decreased by 1.", 0xFF5050),
    (else_try),
        (eq, reg11, 23),
        (troop_raise_attribute, "trp_player", ca_charisma, -1),
        (display_message, "@Your Charisma has decreased by 1.", 0xFF5050),
    (else_try),
        (eq, reg11, 25),
        (troop_raise_skill, "trp_player", skl_persuasion, 1),
        (display_message, "@Your Persuasion skill has increased by 1.", 0x50FF50),
    (try_end),
    (play_sound, "snd_achievement_screen_fanfare"),
    (start_presentation, "prsnt_achievement_notify"),
],
[
]),

("ghostlady_knocked_out", 0,
"The murderous scribe turns out to be very good with a blade, and despite your skill, quickly bests you.  Conciousness abruptly returns when the castle guards pour cold water over you; wounded, but more or less in one piece.  To your angry demand to know why they did not aid you, they reply that it is not their job to attack scribes.  The Scribe has fled.  You reflect bitterly that he will never be brought to justice now,  because of your ineptitude.",
"none", [],
[
    ("continue", [],
    "Continue...",
    [
        (jump_to_menu, "mnu_town"),
    ], "."),

]),

("heartbeat_quest", 4096,
"You receive an urgent message!^^    Your steward, {s8}, of {s2}, has sent you an urgent summons.  There are events that need your attention.^^ He asks that you return to {s2} with all haste.^ ^ There may be negative consequences if you refuse this request...",
"none", 
[
    (set_background_mesh, "mesh_pic_messenger"),
    (party_get_slot, ":var_0", "$g_notification_menu_var1", 293),
    (str_store_troop_name, s8, ":var_0"),
    (str_store_party_name, s2, "$g_notification_menu_var1"),
],
[
    ("heartbeat_quest_accept", [],
    "Send a return message that you will return shortly!",
    [
        (change_screen_return),
    ], "."),

    ("heartbeat_quest_reject", [],
    "Decline the request, you have better things to do.",
    [
        (display_log_message, "@ Your party members grumble at your refusal to help those you have sworn to protect."),
        (call_script, "script_change_player_honor", -1),
        (call_script, "script_change_player_party_morale", -5),
        (call_script, "script_change_player_relation_with_center", "$g_notification_menu_var1", -5),
        (party_set_slot, "$g_notification_menu_var1", 296, 0),
        (change_screen_return),
    ], "."),

]),

("notification_kingdom_restoration", 0,
"Restoration^^{s10} and another {reg1} lords have renounced their allegiance to the {s12} and restorated their home kingdom: {s11}. Their leader, {s9} expresses their goodwill to {s8}.",
"none", 
[
    (faction_get_slot, ":var_0", "$g_notification_menu_var1", slot_faction_leader),
    (str_store_troop_name, s9, ":var_0"),
    (assign, ":var_1", -1),
    (try_for_range, ":var_2", "trp_knight_1_1", "trp_kingdom_1_pretender"),
        (neg|troop_slot_ge, ":var_2", slot_troop_prisoner_of_party, 0),
        (troop_get_slot, ":var_3", ":var_2", slot_troop_original_faction),
        (eq, ":var_3", "$g_notification_menu_var1"),
        (store_troop_faction, ":var_4", ":var_2"),
        (this_or_next|eq, ":var_4", "$g_notification_menu_var2"),
        (this_or_next|eq, ":var_4", "$g_notification_menu_var1"),
        (eq, ":var_4", "fac_outlaws"),
        (call_script, "script_change_troop_faction", ":var_2", "$g_notification_menu_var1"),
        (troop_set_slot, ":var_2", slot_troop_occupation, 2),
        (troop_get_slot, ":var_5", ":var_2", slot_troop_wealth),
        (val_add, ":var_5", 5000),
        (troop_set_slot, ":var_2", slot_troop_wealth, ":var_5"),
        (troop_set_slot, ":var_2", slot_troop_spawned_before, 0),
        (val_add, ":var_1", 1),
        (try_begin),
            (eq, ":var_1", 0),
            (str_store_troop_name, s10, ":var_2"),
        (try_end),
    (try_end),
    (troop_set_slot, ":var_0", slot_troop_spawned_before, 0),
    (assign, reg1, ":var_1"),
    (call_script, "script_auto_sell", "$g_notification_menu_var1"),
    (set_fixed_point_multiplier, 100),
    (position_set_x, pos0, 65),
    (position_set_y, pos0, 30),
    (position_set_z, pos0, 170),
    (set_game_menu_tableau_mesh, "tableau_faction_note_mesh_for_menu", "$g_notification_menu_var1", pos0),
    (str_store_faction_name, s11, "$g_notification_menu_var1"),
    (str_store_faction_name, s12, "$g_notification_menu_var2"),
    (store_troop_faction, ":var_6", "trp_player"),
    (try_begin),
        (eq, ":var_6", "fac_player_faction"),
        (assign, ":var_6", "fac_player_supporters_faction"),
    (try_end),
    (str_store_faction_name, s8, ":var_6"),
],
[
    ("continue", [],
    "Continue...",
    [
        (try_for_range, ":var_0", "fac_player_faction", "fac_kingdoms_end"),
            (neg|eq, ":var_0", "$g_notification_menu_var1"),
            (neg|eq, ":var_0", "$g_notification_menu_var2"),
            (call_script, "script_diplomacy_start_peace_between_kingdoms", ":var_0", "$g_notification_menu_var1", 0),
        (try_end),
        (call_script, "script_diplomacy_start_war_between_kingdoms", "$g_notification_menu_var2", "$g_notification_menu_var1", 1),
        (call_script, "script_update_all_notes"),
        (change_screen_return),
    ], "."),

]),

("manage_loot", 0,
"{s30}",
"none", 
[
    (try_begin),
        (troop_slot_eq, "trp_loot_pool", 188, 0),
        (troop_slot_eq, "trp_loot_pool", 189, 0),
        (assign, reg0, 10000),
        (assign, reg1, 10),
        (str_store_string, s30, "str_to_manufacture_a_carriage"),
    (else_try),
        (troop_get_slot, ":var_0", "trp_loot_pool", 188),
        (troop_get_slot, ":var_1", "trp_loot_pool", 189),
        (neg|ge, ":var_0", ":var_1"),
        (store_sub, reg2, ":var_1", ":var_0"),
        (str_store_string, s30, "str_the_manufacture_of_your_carriage"),
    (else_try),
        (str_store_string, s30, "str_manage_loot"),
    (try_end),
],
[
    ("continue", 
    [
        (troop_slot_eq, "trp_loot_pool", 189, 0),
        (store_troop_gold, ":var_0", "trp_player"),
        (ge, ":var_0", 10000),
    ],
    "Continue...",
    [
        (troop_remove_gold, "trp_player", 10000),
        (troop_set_slot, "trp_loot_pool", 189, 10),
        (troop_set_slot, "trp_loot_pool", 188, 0),
        (jump_to_menu, "mnu_camp"),
    ], "."),

    ("go_back_dot", [],
    "Go back.",
    [
        (jump_to_menu, "mnu_camp"),
    ], "."),

]),

("severance_of_prisoner_begin", 0,
"you sure you want to disband all prisoners in the city to slaves?",
"none", [],
[
    ("yes", [],
    "Yes...",
    [
        (assign, ":var_0", 0),
        (assign, ":var_1", 0),
        (assign, "$g_talk_troop", "trp_ramun_the_slave_trader"),
        (party_get_num_prisoner_stacks, ":var_2", "$current_town"),
        (try_for_range_backwards, ":var_3", 0, ":var_2"),
            (party_prisoner_stack_get_troop_id, ":var_4", "$current_town", ":var_3"),
            (neg|troop_is_hero, ":var_4"),
            (party_prisoner_stack_get_size, ":var_5", "$current_town", ":var_3"),
            (call_script, "script_game_get_prisoner_price", ":var_4"),
            (assign, ":var_6", reg0),
            (val_mul, ":var_6", ":var_5"),
            (val_add, ":var_0", ":var_5"),
            (val_add, ":var_1", ":var_6"),
        (try_end),
        (assign, ":var_7", "$g_move_heroes"),
        (assign, "$g_move_heroes", 0),
        (call_script, "script_party_remove_all_prisoners", "$current_town"),
        (assign, "$g_move_heroes", ":var_7"),
        (store_div, ":var_8", ":var_1", 1000),
        (try_begin),
            (ge, ":var_8", 1),
            (call_script, "script_change_center_prosperity", "$current_town", ":var_8"),
        (try_end),
        (jump_to_menu, "mnu_center_manage"),
    ], "."),

    ("go_back", [],
    "Go back",
    [
        (jump_to_menu, "mnu_center_manage"),
    ], "."),

]),


]